Результатов поиска: 226: Biography

Список разделов Поиск

Поисковый запрос: +Biography

Re: Скрипты для foo_uie_wsh_panel_mod

NikosColev, рекомендую Вам использовать https://hydrogenaud.io/index.php?topic=112914.msg978270#msg978270 скрипт заточенный под Spider Monkey Panel

здесь автор не отвечает, и появляется раз в квартал, это вынудило меня искать более продвинутые компоненты, чего и вам советую :wink:

Спойлер
биография

ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ПРЕДОСТАВЛЯЕТСЯ ОБЛАДАТЕЛЯМИ АВТОРСКИХ ПРАВ И СОСТАВЛЯМИ «КАК ЕСТЬ», И ЛЮБЫЕ ЯВНЫЕ ИЛИ ПОДРАЗУМЕВАЕМЫЕ ГАРАНТИИ, ВКЛЮЧАЯ, НЕ ОГРАНИЧИВАясь, ПОДРАЗУМЕВАЕМЫЕ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННОЙ ЦЕЛИ, ОТКАЗЫВАЮТСЯ. НИ ПРИ КАКИХ ОБСТОЯТЕЛЬСТВАХ АВТОРЫ ИЛИ СОСТАВНИКИ НЕ НЕСЕТ ОТВЕТСТВЕННОСТИ ЗА ЛЮБЫЕ ПРЯМЫЕ, КОСВЕННЫЕ, СЛУЧАЙНЫЕ, ОСОБЫЕ, ПРИМЕРНЫЕ ИЛИ КОСВЕННЫЕ УБЫТКИ (ВКЛЮЧАЯ, НО НЕ ОГРАНИЧИВАЯСЬ, ЗАКУПКИ ТОВАРОВ ИЛИ УСЛУГ; ПРЕРЫВАНИЕ ДЕЯТЕЛЬНОСТИ), ОДНАКО ВЫЗВАННЫМ И ПО ЛЮБОЙ ТЕОРИИ ОТВЕТСТВЕННОСТИ, ЛИБО ПО КОНТРАКТУ, СТРОГОЙ ОТВЕТСТВЕННОСТИ ИЛИ ПЕРЕДАЧИ (ВКЛЮЧАЯ НЕБРЕЖНОСТЬ ИЛИ Иным образом), ВОЗНИКАЮЩИХ ЛЮБОЙ СПОСОБОМ ИСПОЛЬЗОВАНИЯ ДАННОГО ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ, ДАЖЕ ПРЕДНАЗНАЧЕННАЯ ВОЗМОЖНОСТЬ.


ТРЕБОВАНИЯ

Панель Spider Monkey 1.2.2+
IE9 или новее

Необязательно: FontAwesome: https://github.com/FortAwesome/Font-Awesome/blob/ ... ntawesome-webfont.ttf?raw=true. Настоятельно рекомендуется для лучшего рендеринга некоторых кнопок. Если не установлен, затронутые кнопки возвращаются к другому стилю


УСТАНОВКА

Добавьте панель Spider Monkey в макет обычным способом. Щелкните панель Spider Monkey (или щелкните правой кнопкой мыши и выберите «Настроить»), чтобы открыть редактор. Используйте меню "Файл", чтобы импортировать сценарий биографии.


ОБНОВЛЕНИЕ

Shift + щелкните правой кнопкой мыши и выберите настроить. Используйте меню "Файл" для импорта новой версии.


ФУНКЦИИ

Находит и отображает биографии исполнителей и обзоры альбомов с last.fm + allmusic

Получает и отображает фотографии исполнителей с last.fm

Возможность получать и автоматически сохранять обложки для музыкальных файлов в указанном месте (меню> источники> настройки сервера)

Выбирает и отображает обзоры треков с last.fm

Совместимость с пользовательским интерфейсом по умолчанию (DUI) и пользовательским интерфейсом столбцов (CUI)

Поддерживает прозрачность (требуется CUI и разделитель стека панелей или аналогичный)

Универсальный дисплей

Установите предпочтительный исходный порядок

Простые переключатели:

Щелчок левой кнопкой: переключает режим: исполнитель или альбом. Возможность использовать двойной щелчок, если это необходимо (меню> макет> параметры)

Нажатие средней кнопки: переключение между текстом или изображением и двойным режимом (имеется изображение, текст и т. Д.). Переключить также в меню правой кнопки мыши

По умолчанию двойной режим работает в автоматическом стиле. Автоматический стиль можно отключить, чтобы всегда отображать изображение + текст, если это необходимо (меню> макет> параметры)

Автообновление источников и дополнительное принудительное обновление в меню правой кнопки мыши

Для last.fm можно установить язык (меню> источники> язык last.fm)

Стили макета: предустановки для изображения сверху, слева, снизу или справа. Фристайл, позволяющий размещать изображения и текст в любом месте. Возможность создания новых стилей. Нажмите CTRL с указателем мыши, чтобы изменить макеты (панель должна иметь фокус [например, щелкните по ней])

Предустановки темной, смешанной и светлой тем

Сначала сводка - текстовый вариант

Параметры изображения: автоматическое увеличение при наведении указателя мыши, автозаполнение, настраиваемое выравнивание, граница, отражение, точки поиска или полоса и / или счетчик, когда> 1 изображение, тени и эффекты плавного перехода (меню> изображение). Отражение: силу можно регулировать с помощью Shift + колесико мыши над изображением; размер и градиент можно настроить в свойствах панели

Эффекты наложения

Заголовок: включить: меню> макет. Clickable> переключает источник. Поддерживает форматирование заголовков (введите в свойствах панели). Поля, относящиеся к биографии% BIO_ALBUMARTIST%,% BIO_ARTIST%,% BIO_ALBUM% и% BIO_TITLE%, обычно должны использоваться там, где это необходимо, для обеспечения правильного отображения

Рейтинг: опционально показывать рейтинги альбомов last.fm и allmusic в заголовке, на отдельной строке или в тексте

Плавная прокрутка текста

Дискретная полоса прокрутки по умолчанию; можно изменить размер / скрыть. Доступны другие типы полос прокрутки, включая тематические окна. Шаг прокрутки можно настраивать (сенсорные панели, вероятно, лучше всего работают с шагом 1). Для прокрутки страницы щелкните полосу прокрутки, установите шаг прокрутки на страницу или используйте PgDn / PgUp.

Сенсорное управление (включить: меню> макет> параметры)

Для переключения между изображениями можно использовать клавиши со стрелками влево и вправо. PgUp & PgDn работает с текстом. Панель должна иметь фокус и т. Д.

Статистика: опционально отображать скробблы и слушателей last.fm, если они доступны (свойства панели> Статистика Last.fm ...)

Цвета и шрифты: устанавливаются в настройках foobar2000 для DUI или CUI

Размер шрифта: задается шрифтом списка воспроизведения DUI или шрифтом списка CUI. Или используйте наведение мыши с помощью CTRL + колесико мыши, чтобы увеличить размер шрифта (сбрасывается, если размер шрифта пользовательского интерфейса изменился). Заголовок масштабируется независимо

Размер шрифта всплывающей подсказки: устанавливается с помощью «Zoom Tooltip (%)» в свойствах панели.

Дополнительные настраиваемые параметры цвета / шрифта находятся в свойствах панели


СОЗДАВАЙТЕ СТИЛИ И УПРАВЛЯЙТЕ ими (меню> макет)

Поддерживаются два движка стилей

1) Авто. Простой стиль, который используется предустановленными стилями вверху, слева, внизу или справа. Для настройки нажмите CTRL с указателем мыши. Перепозиционирование рассчитывается автоматически. Прокладка> свойства панели. Выравнивание изображения> меню

2) Фристайл. Используется предустановкой стиля наложения. Предлагает стиль перетаскивания изображений и текстовых полей, а также наложение текста. Нажмите CTRL с указателем мыши, чтобы отобразить поля перетаскивания. Эффекты наложения:

Тип наложения: меню> макет> темы
Сила наложения: Shift + колесо мыши над текстом
Прочие настройки наложения: свойства панели («Наложение ...»)

Выравнивание изображения> меню
Отступы> свойства панели [применяется внутри ящиков]

Меню предлагает варианты для создания новых макетов вольного стиля + переименования, удаления и экспорта пользовательских стилей или сброса макетов. Новые макеты для фристайла основаны на текущем макете


КНОПКА БОЛЬШЕ ПРЕДМЕТОВ: ПОДОБНЫЕ ИСПОЛНИТЕЛИ, ТОП-АЛЬБОМЫ И ДОПОЛНИТЕЛЬНЫЕ ТЭГИ (включить: щелкните правой кнопкой мыши> меню> источники)

Выпадающее меню (вверху слева), которое позволяет отображать информацию, относящуюся к текущему элементу:

Похожие исполнители, несколько полей и многозначные теги: получение и отображение биографий и фотографий

Лучшие альбомы: получение и отображение обзоров и изображений для обзора

Формат заголовка может быть установлен для отображения источника информации, если требуется, например

Биография: заголовок, формат заголовка для идентификации похожих или помеченных художников:
$ if2 ($ if (% MORE_ITEM%, [% BIO_ARTIST%: аналогично $ meta (artist, 0)], [% BIO_ARTIST%]), Artist Unknown)

Обзор: формат заголовка для определения лучших альбомов:
$ if2 (% BIO_ALBUMARTIST%, исполнитель неизвестен) $ if2 ($ if (% MORE_ITEM%, [-% BIO_ALBUM% '[' Top Album ']'], [-% BIO_ALBUM%]), - Album Unknown)

% MORE_ITEM% доступен для использования в заголовках. Оценивается как истинное или ложное

Опция автоматического цикла

Можно установить количество отображаемых похожих исполнителей (0-10) ["Меню> Источники> Настройки сервера" (biography.ini)]

Используйте наведение мыши с помощью CTRL + колесико мыши, чтобы увеличить размер кнопки

Техническая информация
Многополевые и многозначные теги расширяют все поля, на которые ссылается "% BIO_ARTIST%" в biography.ini, и включают многозначные значения. Дополнительные поля могут быть добавлены в конце оператора $ if3 и т. Д. Из-за ограничений поиска новые полностью музыкальные биографии не могут быть извлечены, но уже существующие могут быть загружены. Также имеется расширенная опция в «Меню> Источники> Настройки сервера» (biography.ini) для кэширования новых * данных, полученных с помощью кнопки «Дополнительная информация», отдельно от основного места, если это необходимо. Это настраивается путем применения «Найти»> «Заменить» к основным шаблонам сохранения, чтобы сохранить основные шаблоны сохранения. Несколько пар "Найти> Заменить" можно разделить знаком |, например
yttm> yttm \ bio_supplemental | данные пользователя> данные пользователя \ дополнительные
Заменяет:
yttm с yttm \ bio_supplemental &
пользовательские данные с пользовательскими данными \ дополнительными
* основные места сохранения будут по-прежнему использоваться для элементов, обнаруженных как находящиеся в медиатеке, стандартные элементы, такие как воспроизводимые треки и элементы, уже существующие


ЗАМОК

Возможность заблокировать основного исполнителя, альбом и трек текущими. Требуется включить "Меню> Источники> Кнопка" Показать больше элементов ". Переключите блокировку / разблокировку средним нажатием кнопки. Кнопка меняется, показывая состояние блокировки. По-прежнему доступны другие пункты меню, переключатели и т. Д. More flyout также имеет возможность автоматически подключаться при просмотре истории и подобных исполнителей и т. Д.


НЕАКТИВИРОВАТЬ

Биографию можно сделать полностью неактивной. Нет поиска в Интернете. Нет загрузки текста или изображения. Включить: SHIFT + щелчок правой кнопкой мыши> меню> отключить


МЕНЮ (ПРАВЫЙ ЩЕЛЧОК)

Содержит часто используемые настройки. По умолчанию «Вставить текст из буфера обмена» и «Записать теги в выбранные файлы» для отображения требуется нажатие клавиши Shift, а «Списки воспроизведения» не отображаются. Поведение можно изменить в свойствах панели: «Пункты меню ...»


СВОЙСТВА ПАНЕЛИ

Свойства панели также применяются к отдельным панелям биографии и содержат настройки, которые обычно нужно менять нечасто.

Доступ по щелчку правой кнопкой мыши

*** ВСЕГДА ОБЕСПЕЧИВАЙТЕ ЗАПЯТУЮ "," СЕПАРАТОРЫ, ИСПОЛЬЗУЕМЫЕ В СВОЙСТВАХ ПАНЕЛИ ***

Свойства панели можно сбросить до значений по умолчанию, удалив -> применить

Доступность пользовательских значков может зависеть от установленных шрифтов. Шрифт значка можно установить в свойствах панели. Можно вставлять символы шрифта. Рекомендуемые шрифты для значков: Segoe UI Symbol, Segoe MDL2 Assets, FontAwesome, Guifx v2 Transports и Wingdings. Вертикальное смещение и зазор обеспечивают небольшую регулировку, достаточную для точной настройки положения значка.


БИОГРАФИЧЕСКИЙ СЕРВЕР

«Настройки сервера» находятся в biography.ini и применяются ко всем панелям биографии: foobar2000 (profile) \ yttm \ biography.ini

Меню> Источники> Настройки сервера можно использовать для открытия biography.ini.

Содержит настройки, для каких источников следует выполнять автоматическую выборку, переназначение имен, места сохранения и различные прочие и расширенные параметры.


СПАСТИ

Шаблоны сохранения по умолчанию упорядочивают информацию по типу и источнику. Если вы предпочитаете организовывать по исполнителям, можно использовать следующие

[СПАСТИ]
Обзор альбома [Allmusic] Папка =% profile% \ user-data \% BIO_ALBUMARTIST% \ allmusic
Обзор альбома [Lastfm] Folder =% profile% \ user-data \% BIO_ALBUMARTIST% \ lastfm
Биография [Allmusic] Папка =% profile% \ user-data \% BIO_ARTIST% \ allmusic
Биография [Lastfm] Folder =% profile% \ user-data \% BIO_ARTIST% \ lastfm
Изображение [Исполнитель] Папка =% profile% \ user-data \% BIO_ARTIST%
Изображение [Обзор] Папка =% profile% \ user-data \% BIO_ARTIST%


БИОГРАФИИ И ОТЗЫВЫ АЛЬБОМОВ ИСПОЛНИТЕЛЕЙ

Скрипт автоматически обновляет кэшированные данные в соответствии со временем «Истечение срока действия кеша» в biography.ini, если исполнитель или альбом воспроизводятся / выбираются. По умолчанию 28 дней можно легко увеличить до 90-180 + дней. Биографии веб-сайтов развиваются медленно и нечасто, обычно не более 1-2 раз в год для действующих художников и никогда или редко для неактивных художников. Обзоры альбомов: allmusic не меняется и не обновляется автоматически; last.fm периодически меняются. Принудительное обновление в меню, вызываемом правой кнопкой мыши, отменяет время истечения срока действия кэша и немедленно обновляет включенные источники.


ТАМОЖЕННЫЕ БИОГРАФИИ И ОТЗЫВЫ

«SHIFT * + щелкните правой кнопкой мыши> Меню> Источники> Вставить из буфера обмена». Флаг «Пользовательская биография» или «Пользовательский обзор» используется для предотвращения попыток биографии автоматически обновлять любые пользовательские биографии и обзоры, и это следует оставить на месте. «Принудительное обновление» отменяет флаг. Пункты меню отображаются серым цветом в режиме «только изображение» или если отсутствуют данные из буфера обмена или требуемые имена исполнителей / альбомов. * Может быть установлено, что сдвиг не требуется в свойствах панели: «Пункты меню ...»


НАЗВАНИЕ АЛЬБОМА АВТОЧИСТКА (необязательно)

При необходимости удаляет ключевые слова перед поиском в сети, например «Deluxe Version», «[2011 - Remaster]», «Expanded Edition» и многие другие. Улучшает результаты поиска, если такие фразы используются в названиях альбомов. По умолчанию выключено. Включить в biography.ini («РАЗЛИЧНЫЙ ЗАГОЛОВОК»)

Метод поиска, если включен
Охватывает. Сначала выполните поиск по полному названию альбома, так как часто доступны варианты обложки. Если обложка не найдена, ищите, используя вырезанное имя "ядра", если оно отличается. Например, попробуйте «Мадонна - сердце мятежника (Super Deluxe Edition)»; если обложка не найдена, попробуйте "Мадонна - сердце мятежника"
Обзоры альбомов. Искать с вырезанным "основным" именем, поскольку имена с "дополнительной информацией" в большинстве случаев не работают или находят некачественный обзор.

Метод поиска, если отключен
Обложки и обзоры альбомов. Искать по полному названию альбома


ИЗОБРАЖЕНИЯ ХУДОЖНИКОВ

Они взяты с last.fm. «Настройки сервера» (biography.ini) позволяют указать количество изображений для каждого художника. В меню изображения есть опция черного списка, чтобы остановить отображение и загрузку нежелательных изображений (данные черного списка сохранены в профиле fb2k \ yttm \ blacklist_image)

Если вы используете функциональный загрузчик изображений художника с другим плагином / скриптом, который сохраняет изображения по папкам, отключите сборщик биографий и введите расположение папки в biography.ini. Локация будет отслеживаться в реальном времени.


ОБЛОЖКИ И ОБЗОР ИЗОБРАЖЕНИЙ

Они взяты с last.fm

[ОБЛОЖКИ: МУЗЫКАЛЬНЫЕ ФАЙЛЫ]
Включите автосохранение, чтобы обложки музыкальных файлов сохранялись в указанном месте. Цель состоит в том, чтобы получить недостающие обложки. Если автосохранение включено, ищет, когда невозможно загрузить обложку в соответствии с основными настройками foobar2000 (отображение> обложка альбома> передняя обложка> шаблоны поиска), и нет сохраненной обложки

[AUTO-FETCH]
Изображение [Review] Auto-Fetch: применяется к запросам «Дополнительные элементы меню»: выбирает изображения для обзора

Настройки находятся в «Настройках сервера» (biography.ini).


ДИСПЛЕЙ ИЗОБРАЖЕНИЯ

Охватывает

Проверяет: foobar2000> настройки> отображение> обложки альбомов> шаблоны + места сохранения и, если включено, циклическое расположение

Изображения художников

Проверяет: расположение папки изображений исполнителя last.fm, затем foobar2000> настройки> отображение> обложка альбома> шаблоны исполнителей. Если фото установлено на исполнителя, проверяется только последний

Шаблоны возврата или изображения-заглушки можно установить в foobar2000> настройки> отображение> обложка альбома.

Поиск и счетчик изображений

Seeker поддерживает кликабельные точки, а также стиль полосы для выбора изображения. Оба можно перетащить. Счетчик необязательно + может отображаться отдельно. Настройки: меню> изображение> искатель. Показать, когда> 1 изображение
Технические примечания
1) Некоторые раскладки фристайла несовместимы с искателем и счетчиком. В этих случаях они отключены (пункт меню неактивен). Этого можно избежать, если изображение и текстовые поля не перекрываются.
2) Позиционирование искателя. Макеты в стиле левого и правого изображения обычно приводят к изменению высоты изображения при загрузке разных изображений. Тем не менее, искатель должен оставаться на той же высоте, чтобы его можно было перетаскивать и щелкать, и поэтому относительно высоты изображения положение искателя может варьироваться. Этого можно избежать, установив высоту изображения с помощью:
1) Круглые изображения
2) Автозаполнение с макетом произвольного стиля («меню> макет> создать новый стиль»), если затем требуется дополнительная настройка поля изображения.


ОТОБРАЖЕНИЕ ИЗОБРАЖЕНИЙ ДРУГИМИ Зрителями ARTWORK и плейлистами

Большинство компонентов загружают изображения через основные настройки foobar2000 (отображение> обложка альбома). Недействительные символы в именах папок и файлов обрабатываются автоматически. Примеры с настройками по умолчанию:

Отображение выбранных обложек: добавьте в шаблоны поиска "Передняя обложка" следующие строки:
обложка.*

Отображение выбранных изображений исполнителей: добавьте следующее в шаблоны поиска «Исполнитель»:
XX \ foobar2000 \ yttm \ art_img \ $ cut (% artist%, 1) \% artist% \ *
где XX - ваш собственный путь. Для каждого художника будет выбрано одно изображение

Если используются многозначные теги, $ meta (artist, 0) и т. Д. Могут работать лучше, чем% artist%

Вышеупомянутые стили также можно использовать в источниках графических изображений CUI.

Сценарий всегда заменяет начальные точки в метаданных подчеркиванием в именах папок и файлов. Это потому, что foobar2000 не обрабатывает этот случай автоматически и не загружает изображения, если в какой-либо папке в шаблоне поиска есть начальная точка ".". Этот сценарий встречается редко и может игнорироваться большинством пользователей. Но если у вас есть такие художники, как ".38 Special", подумайте об использовании вместо этого следующего стиля, который обеспечит загрузку изображений художников для всех художников:
XX \ foobar2000 \ yttm \ art_img \ $ replace ($ cut (% artist%, 1),., _) \ $ If ($ stricmp ($ cut (% artist%, 1),.), _ $ Substr (% artist%, 2, $ len (% artist%)),% artist%) \ *


НАПИСАНИЕ ТЕГОВ

«SHIFT * + щелчок правой кнопкой мыши> меню> Записать теги для выбранных треков» (отображается серым цветом, если файлы списка воспроизведения не выбраны). * Может быть установлено, что сдвиг не требуется в свойствах панели: «Пункты меню ...»

В меню показаны теги, которые нужно записать. Включите / отключите по мере необходимости. Написанные теги многозначны, за исключением рейтинга альбома AllMusic

Доступные теги:

Жанр альбома AllMusic
Альбом Mood AllMusic
Рейтинг альбома AllMusic
Тема альбома AllMusic
Исполнитель Жанр AllMusic
Жанр альбома Last.fm
Жанр исполнителя Last.fm
Локаль Last.fm
Похожие исполнители Last.fm

При необходимости измените имена тегов в настройках сервера (biography.ini)

Все теги пишутся из сохраненных источников (т.е. пишется только существующая информация в уже сохраненных биографиях, обзорах и подобных исполнителях). Это должно работать лучше всего, если вы уже какое-то время пользуетесь биографией. Файлы с отсутствующими тегами обычно можно определить, выбрав "?" вверху просмотров библиотеки и т. д.

По умолчанию теги жанра last.fm очищаются перед записью. Это направлено на удаление тегов, не относящихся к жанру, из списков основных тегов last.fm и сортировку вариантов написания. При необходимости настройте параметры в «ADV.Last.fmGenreTag ...» в свойствах панели; отключите очистку, чтобы записать оригинальные топ-теги

Количество похожих художников для написания может быть установлено (0-100). Из биографии читается до 4-х. Для использования 5+ требуется сохраненный список (сохранение автоматически включается по умолчанию, если для номера установлено значение 5+). Если установлено значение 5+, нет возможности вернуться к чтению 4 в биографии. Если вы пишете> 20 похожих художников, вероятно, потребуется увеличить ограничения на размер в «LargeFieldsConfig.txt» для правильной работы.

Хорошо работает с видами библиотеки, такими как:

Просмотр по жанру альбома AllMusic //% <жанр альбома allmusic>% | [% исполнителя альбома% -]% альбома% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по жанру альбома Last.fm //% <жанр альбома last.fm>% | [% исполнителя альбома% -]% альбома% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по альбому Настроение AllMusic //% <альбомное настроение allmusic>% | [% альбом исполнителя% -]% альбом% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по рейтингу альбома AllMusic //% рейтинга альбома allmusic% | [% альбома исполнителя% -]% альбома% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по теме альбома AllMusic //% <тема альбома allmusic>% | [% исполнитель альбома% -]% альбом% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по исполнителям Жанр AllMusic //% <исполнитель жанр allmusic>% |% artist% |% album% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по исполнителю Жанр Last.fm //% <исполнитель жанр last.fm>% |% artist% |% album% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по городу // $ if ($ meta (locale last.fm, 0), $ meta (locale last.fm, 0) '(' $ meta (locale last.fm, $ sub ($ meta_num (locale last.fm ), 1)) ')' ,?) |% artist% |% album% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр по стране // $ if2 ($ meta (locale last.fm, $ sub ($ meta_num (locale last.fm), 1)) ,?) |% artist% |% album% | [[% discnumber%.] %номер дорожки%. ] [% исполнитель% -]% название%

Просмотр по стране: Город // $ if2 ($ meta (locale last.fm, $ sub ($ meta_num (locale last.fm), 1)) $ if ($ meta_num (locale last.fm) ,: $ meta (locale last.fm, 0)) ,?) |% artist% |% album% | [[% discnumber%.]% tracknumber%. ] [% исполнитель% -]% название%

Просмотр по языку Last.fm //% <locale last.fm>% |% artist% |% album% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Просмотр похожих исполнителей Last.fm //% <похожие исполнители last.fm>% |% artist% |% album% | [[% discnumber%.]% Tracknumber%. ] [% исполнитель% -]% название%

Рейтинг альбома AllMusic написан по шкале от 0 до 10 для облегчения сортировки и обработки запросов.

Locale Last.fm пишет «Основанный в» (группы) или «Родившийся в» (исполнители), как прочитано из биографии last.fm (поддерживает языковые варианты). Тег многозначен для максимальной гибкости. % locale last.fm% или $ meta (locale last.fm) должны отображаться так, как написано в биографии

$ meta (locale last.fm, 0) // возвращает первое значение, обычно город / город, например The Beatles -> Liverpool; Мадонна -> Бэй-Сити

$ meta (locale last.fm, $ sub ($ meta_num (locale last.fm), 1)) // возвращает последнее значение, обычно страну, например United Kingdom или United States

Во время записи тега вся информация сначала считывается с диска и обрабатывается. Поэтому при записи большого количества файлов может возникнуть задержка перед появлением окна выполнения обновления файлов.

Рекомендуется сначала попробовать написать теги для репрезентативного набора файлов, чтобы оптимизировать настройки и убедиться, что он работает должным образом и т. Д. Исполнитель, исполнитель альбома и альбом определяются настройками сервера (biography.ini) для% BIO_ARTIST%,% BIO_ALBUMARTIST% и % BIO_ALBUM%


ПОТЕРЯННАЯ ИНФОРМАЦИЯ

Биография может проверять отсутствующие биографии, обзоры и изображения исполнителей. Поскольку это предназначено для отладки или нишевых пользователей, он доступен как дополнительный пункт меню (по умолчанию не показан). Чтобы отобразить: настройки панели> «Элементы меню Hide-0 Shift-1 Show-2»> установите «Missing Data» на 1 (требуется сдвиг) или 2 (всегда отображается)


ДОПОЛНИТЕЛЬНО: СПОСОБЫ ПОЛЬЗОВАТЕЛЯ

Большинству пользователей эта функция не нужна, поскольку обложки загружаются автоматически через foobar2000> настройки> дисплей> обложки альбомов> шаблоны или из мест сохранения. Включите при необходимости в настройках сервера (biography.ini). Затем сначала будут проверены пользовательские пути к обложке. Для пользовательских путей введите полный путь минус расширение; в отдельных строках можно ввести до 5, что позволяет указать разные местоположения и имена файлов. Поддерживается все форматирование заголовков + абсолютные пути. Используйте $ replace для пользовательской замены недопустимого символа (здесь нет автоматической замены). % BIO_ALBUMARTIST%,% BIO_ARTIST%,% BIO_ALBUM% и% BIO_TITLE% поддерживаются, но не должны использоваться, если стандартные поля работают. % path% ОК, здесь только загрузка, несовместимость сохранения с радиопотоками и т. д.

Пример пути =% profile% \ cover \ $ replace (% album artist% -% album%, /, _, \, _, |, _,:, _, *, _, ", _, <, _,> ,_,?,_) '['%Дата%']'


Marakobes
05.10.2020, 18:45
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 6

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text & Album Info & Picture. www.last.fm
version "09022017"


- изменения на last.fm;
- исправлен "вылет" при старте на пустом плейлисте.
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "09022017"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 600, wh = 600;

var font_name_h = window.GetProperty(" font name: artist", "Arial");
var font_name_t = window.GetProperty(" font name: biography", "Arial");
var font_size_h = window.GetProperty("font size: artist", 12);
var font_size_t = window.GetProperty("font size: biography", 12);
var h_font_style = window.GetProperty(" font style: artist", 1);
var t_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = window.GetProperty(" font size: min", 12);
var max_font_size = window.GetProperty(" font size: max", 16);
var txt_shadow = window.GetProperty(" shadow of the text", true);

var h1_font, h2_font, t_font;
get_font();

function get_font(){
    h1_font = gdi.Font(font_name_h, font_size_h, h_font_style);
    h2_font = gdi.Font(font_name_t, font_size_t, h_font_style);
    t_font = gdi.Font(font_name_t, font_size_t, t_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        h_color = window.GetColorCUI(ColorTypeCUI.text);
        t_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        h_color = window.GetColorDUI(ColorTypeDUI.text);
        t_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, tf_artist, old_artist, album;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\.\/\:\*\?\"\<\>\|]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    if (!n) return;
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

function get_fn(p) {
    if (!p) return;
    return p.replace(/.*\\|\.[^.]+$/g,'')
}

function get_fnext(p) {
    if (!p) return;
    return p.replace(/.*\\/g,'');
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 1);
var selected = 0;
var files = [];
var images = [];
var test_found = 0;
var save_images = window.GetProperty("save images", true);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var txt_y_cycle = 20;
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar170s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var h_x, h1_y, h2_y, t_x, t_x;
var text = "";
var text_not_found = new Array(". . .", ". . .", ". . .");
var s_text = 0;
var h1_char_width;
var h1_text_array = [];
var h1_text_row_height;
var h1_text_visable_rows;
var h2_text_array = [];
var h2_text_row_height;
var h2_text_visable_rows;
var text_row_height;
var text_rows;
var text_visable_rows;
var text_visable_height;
var text_array = [];
var on_text = false;
var on_header = false;
var on_text_down = false;
var refresh_txt = true;

var album_info = window.GetProperty("album info", true);

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");

var lang_query = new Array("", "ru/", "zh/");
var lang_text = new Array("in", "ru", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("artist/album", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();


function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    if (!artist){
        txt_shadow && gr.GdiDrawText( "Nothing found", gdi.Font("Arial",12, 0), RGB(0,0,0), 0 + 1, 0 + 2, ww, wh, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS );
        gr.GdiDrawText( "Nothing found", gdi.Font("Arial",12, 0), h_color, 0, 0, ww, wh, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS );
    }
   
    draw_image(gr);

    if(set_cycle && on_pic){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        txt_shadow && gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, RGB(0,0,0), 0 + 1, txt_y_cycle + 2, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
        gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, t_color, 0, txt_y_cycle, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        if (artist) gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    if(f_info && set_cycle && on_pic){   
        draw_file_info(gr); 
    } 
   
    draw_scrollbar(gr);   
   
    for (var i = 0; i < h1_text_visable_rows; i += 1) {
        try {
            txt_shadow && gr.GdiDrawText( h1_text_array[i], h1_font, RGB(0,0,0), h_x + 1, h1_y + h1_text_row_height * i + 2, ww, wh, DT_LEFT | DT_NOPREFIX );   
            gr.GdiDrawText( h1_text_array[i], h1_font, h_color, h_x, h1_y + h1_text_row_height * i, ww, wh, DT_LEFT | DT_NOPREFIX );   
        } catch(e) {}
    }

    if (album_info && select_p_a == 1){
        for (var i = 0; i < h2_text_visable_rows; i += 1) {
            try {
                txt_shadow && gr.GdiDrawText( h2_text_array[i], h2_font, RGB(0,0,0), h_x + 1, h2_y + h2_text_row_height * i + 2, ww, wh, DT_LEFT | DT_NOPREFIX );   
                gr.GdiDrawText( h2_text_array[i], h2_font, t_color, h_x, h2_y + h2_text_row_height * i, ww, wh, DT_LEFT | DT_NOPREFIX );   
            } catch(e) {}
        }
    }

    for (var i = 0; i < text_visable_rows * 2; i += 2) {
        try {
            txt_shadow && gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, RGB(0,0,0), t_x + 1, t_y + text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, t_color, t_x, t_y + text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 1, logo_img.Height * 1, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = text_rows > text_visable_rows ? text_visable_height * (text_visable_rows / text_rows) : 0;
    if (text_rows > text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_alpha = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(h_color), getGreen(h_color), getBlue(h_color), sb_alpha);
   
    scrollbar && gr.FillSolidRect(sb_x, t_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist); tf_artist = Eval("%artist%")} else {artist = ""; tf_artist = ""};
    if (artist != old_artist){
        check_folder(artist_folder_path(artist));
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    test_found = 0;
    window.Repaint();
   
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    var url1 = ("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]+ "?page=" + 1); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var an = div.getElementsByTagName("p");
                var urls = [];
                var name = [];      // album name
                var name2 = [];     // album name
                var name3_tmp = []; // release date
                var name3 = [];     // release date
                var img_exist = [];
 
                if (select_p_a == 1){ 
                    for (i = 0; i < an.length; i++) {   
                        if (an[i].className == "album-grid-item-main-text" ){ 
                            name2.push(an[i].innerHTML.replace(/(&amp;)/g,'&'));
                        }
                    } 

                    for (i = 0; i < an.length; i++) {   
                        if (an[i].className == "album-grid-item-aux-text" ){
                            name3_tmp.push(an[i].innerHTML.replace(/\,/g,''));
                        }
                    }
                   
                    for (i = 0; i < name3_tmp.length; i++) {   
                        if (i%2 != 0) {                           
                            name3.push(name3_tmp[i].replace(/^\s+|\s+$/g,'').replace(/^(.*)\s/g,''));
                        }
                    }
                   
                    if (name3) utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album-grid-item-aux-text", "name3", name3);
                }

                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("https://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("https://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {   
                            if (data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) { 
                                urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                                name.push(data[i].alt.replace(/^(.*)'.*$/g,'$1').replace(/^(.*?)'/g,''));
                                img_exist.push(i - 3);
                            }
                        } 
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "img_exist", "img_exist", img_exist);
                    }
                }

                var found = urls.length;
                test_found = found;
               
                for (i = 0; i < Math.min(urls.length, limit); i++) { 
                    if (select_p_a == 0){                   
                        var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                        WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                    }

                    if (select_p_a == 1){
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name2[img_exist[i]]);
                        var file2 = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";   
                        WshShell.Run(vbs + " " + urls[i] + " " + file2, 0, false);
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
                get_text();
            }
        }
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();

    if (files.length > images.length){
        images = [];
        files = naturalSort(files);
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img || !ww || !wh) return;
   
    var scale_w = ww / img.Width;
    var scale_h = wh / img.Height;
    var scale = Math.max(scale_w, scale_h);

    var nww = Math.round(img.Width * scale);
    var nwh = Math.round(img.Height * scale)

    return img.Resize(nww, nwh, 2);
    img && img.Dispose();
}

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function clear_txt_var() {
    album = "";
    s_text = 0;
    text = "";
    text_array = [];
    get_text_array();
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";

    if (fso.FolderExists(artist_folder_path(artist))){
        if (fso.FileExists(b_text_file)){
            text = utils.ReadTextFile(b_text_file);
            get_text_array();
        } else{
            get_lastFM_b_text(b_text_file);
        }
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
               
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_text_array() {
    h_x = txt_x + t_margin;
    h1_y = txt_y + t_margin;
    t_x = txt_x + t_margin;
   
    h_string_width = scrollbar ? Math.max(ww - t_x - t_margin, 0) : Math.max(ww - t_x - t_margin, 0);
    string_width = scrollbar ? Math.max(ww - t_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - t_x - t_margin, 0);
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();
   
    if (artist) h1_char_width = temp_gr.CalcTextWidth(artist.substr(0,1), h1_font);

    h1_text_row_height = temp_gr.CalcTextHeight("Header_1", h1_font);
    h1_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - h1_y));
    h1_text_visable_rows = Math.max(1, Math.floor(h1_text_visable_area / h1_text_row_height));

    if (tf_artist) {
        var h1_text_array_tmp = temp_gr.EstimateLineWrap(tf_artist.replace(/^\s+|\s+$/g, ""), h1_font, h_string_width).toArray();

        h1_text_array = [];
        for (var i = 0; i < h1_text_array_tmp.length; i += 2) {
            h1_text_array.push(h1_text_array_tmp[i].replace(/^\s+|\s+$/g, ""));
        }
    }
   
    h2_y = h1_y + h1_text_array.length * h1_text_row_height;

    h2_text_row_height = temp_gr.CalcTextHeight("Header_2", h2_font);
    h2_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - h2_y));
    h2_text_visable_rows = Math.floor(h2_text_visable_area / h2_text_row_height);

    if (album) {
        var h2_text_array_tmp = temp_gr.EstimateLineWrap(album.replace(/^\s+|\s+$/g, ""), h2_font, h_string_width).toArray();

        h2_text_array = [];
        for (var i = 0; i < h2_text_array_tmp.length; i += 2) {
            h2_text_array.push(h2_text_array_tmp[i].replace(/^\s+|\s+$/g, ""));
        }
    }
   
    text_row_height = temp_gr.CalcTextHeight("Biography", t_font);
   
    t_y = (album_info && select_p_a == 1 ? h2_y + h2_text_array.length * h2_text_row_height : h1_y + h1_text_array.length * h1_text_row_height) + text_row_height;

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        text_array = [];
        if (text) text_array = temp_gr.EstimateLineWrap(text, t_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    text_rows = text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - t_y));
    text_visable_rows = Math.floor(b_text_visable_area / text_row_height);
    text_visable_height = text_visable_rows * text_row_height;

    if (text_visable_rows + s_text > text_rows && s_text > 0) {
        s_text = (text_rows - text_visable_rows);
    }

    scrollbar_k = text_visable_height / text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    if (fso.FolderExists(artist_folder_path(artist))){
        try {
            file = fso.OpenTextFile( p, 2, true, -1)
            file.Write(t);
            file.Close();
        } catch(e) {
            return;
        }
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 12, lang_text[2] + " text");   
    _menu.CheckMenuRadioItem(10, 12, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 20, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 21, "Follow selected track");   
    _menu.CheckMenuRadioItem(20, 21 , selection_mode + 20);   
    _menu.EnableMenuItem(selection_mode + 20, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 30, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 31, "Albums pictures");   
    _menu.CheckMenuRadioItem(30, 31 , select_p_a + 30);   
    _menu.EnableMenuItem(select_p_a + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 40, "Album info");
    _menu.CheckMenuItem(40, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 50, "last.fm Artist");
    _menu.AppendMenuItem(IS_ARTIST, 51, "last.fm Albums");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Fade effect");
    _menu.CheckMenuItem(60, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 70, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 71, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 72, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 73, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 74, align_mode_a[4]);
    _firstgroup.CheckMenuRadioItem(70, 74, align_mode + 70);
    _firstgroup.EnableMenuItem(align_mode + 70, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 80, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 81, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 82, "High");
    _secondgroup.CheckMenuRadioItem(80, 82, download_quality + 80);
    _secondgroup.EnableMenuItem(download_quality + 80, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _thirdgroup = window.CreatePopupMenu();
   
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _thirdgroup.AppendTo(_menu,MF_STRING,  "Copy to folder containing track...");
   
    _thirdgroup.AppendMenuItem(MF_STRING, 90, "Copy file");
    _thirdgroup.AppendMenuItem(MF_STRING, 91, "Copy files");
   
    _menu.AppendMenuItem(MF_STRING, 100, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Save images and text");
    _menu.CheckMenuItem(110, save_images);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 120, "Load album image");

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 500, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 510, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 520, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
    case 12:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 20:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 21:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 30:
        select_p_a = 0;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 31:
        select_p_a = 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 40:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 50:
        WshShell.run("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 51:
        WshShell.run("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + "+albums");
        break;
    case 60:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 70:
    case 71:
    case 72:
    case 73:
    case 74:
        align_mode = ret - 70;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 80:
    case 81:
    case 82:   
        download_quality = ret - 80;
        window.SetProperty("download quality", download_quality);
        break;
    case 90:
        select_file = 0;
        copy_files();
        break;
    case 91:
        select_file = 1;
        copy_files();
        break;
    case 100:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 110:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 120:
        search_lastFM_album_img();
        break;
    case 500:
        try {
            window.Reload();   
        } catch(e) {};
        break;
    case 510:
        window.ShowProperties();
        break;   
    case 520:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        for (var i = 0; i < files.length; i += 1) {
            if (get_fn(files[i]).replace(/^(.*?)_|_.*/g,'') == 0 && images.length > 0) {
                next_image(0);
                window.ClearInterval(timer);
             }                 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "https://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "https://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_header = x >= txt_x && x < ww && y >= txt_y && y < t_y ? true : false;
    on_text = x >= txt_x && x < sb_x && y >= t_y && y <= wh ? true : false;
   
    on_sb =  x >= sb_x && x < ww && y >= t_y && y <= wh ? true : false;
    on_pic = !on_text && !on_header && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;
       
        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - t_margin * 2 - h1_char_width ? ww - t_margin * 2 - h1_char_width : txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (h1_text_row_height + t_margin) ? wh - (h1_text_row_height + t_margin) : txt_y;

        get_text_array();
    }

    if (on_sb_down && scrollbar && text_rows > text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (text_rows - text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : text_rows - text_visable_rows : 0;
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
   
    if (on_header && on_text_down) {
        txt_hiden = false;
        window.SetProperty("txt hiden", txt_hiden);
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !set_cycle && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if ((on_header || on_text || on_sb) && !ShiftDown){
        if (text_rows > text_visable_rows){
            if (delta < 0) {s_text = text_rows - s_text <= text_visable_rows ? text_rows - text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if ((on_header || on_text) && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (on_header && delta < 0) {font_size_h = font_size_h <= min_font_size ? min_font_size : font_size_h - 2;};
        if (on_header && delta > 0) {font_size_h = font_size_h >= max_font_size ? max_font_size : font_size_h + 2;};
        window.SetProperty("font size: artist", font_size_h);
        if (on_text && delta < 0) {font_size_t = font_size_t <= min_font_size ? min_font_size : font_size_t - 2;};
        if (on_text && delta > 0) {font_size_t = font_size_t >= max_font_size ? max_font_size : font_size_t + 2;};
        window.SetProperty("font size: biography", font_size_t);
        get_font();
        refresh_txt = true;
        get_text_array();
    }

    if (on_pic && set_cycle && ShiftDown) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_header || on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (h1_text_row_height + t_margin) && txt_y >= 0 ? wh - (h1_text_row_height + t_margin) : txt_y;
   
    refresh_txt = true;
    get_text_array();
    get_pic()
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 2: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 3: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 4: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

var select_file = 0;

function copy_files(){
    var destination_path;
    var tmp_files = [];
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;

    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + "tmp_lastFM_img\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";

    if (select_file == 0){
        files = naturalSort(files);
        tmp_files.push(files[selected]);
        var input_box_text = "Copy  " + nl + nl + get_fnext(tmp_files[0]) + nl + "file to";
    } else {
        tmp_files = files;
        var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";
    }

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");
   
    if (string){
        destination_path = folder_exists(string);
       
        if(fso.FolderExists(destination_path)) {
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }else{
            copy_files();
        }
    }
}

function copy_files_to_folder(p, f, pa){
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

function naturalSort(stringArray) {
    var xor = function(a, b) {
        return a ? !b : b;
    }
    var isDigit = function(chr) {
        var charCode = function(ch) {
            return ch.charCodeAt(0);
        };
        var code = charCode(chr);
        return (code >= charCode('0')) && (code <= charCode('9'));
    }
    var splitString = function(str) {
        var from = 0;   
        var index = 0;
        var count = 0; 
        var splitter = {};

        splitter.count = function () {
            return count;
        }
        splitter.next = function() {
            if (index === str.length) {
                return null;
            }
            while(++index) {
                var currentIsDigit = isDigit(str.charAt(index - 1)); 
                var nextChar = str.charAt(index);
                var currentIsLast = (index === str.length);
                var isBorder = currentIsLast || xor(currentIsDigit, isDigit(nextChar));       
                if (isBorder) {
                var part = str.slice(from, index);
                    from = index;
                    count++;
                    return {
                        IsNumber: currentIsDigit,
                        Value: currentIsDigit ? Number(part) : part
                    }
                }
            }
        }
        return splitter;
    }
    var compareStrings = function(str1, str2) {
        var compare = function(a, b) { 
            return (a < b) ? -1 : (a > b) ? 1 : 0;
        }
        var splitter1 = splitString(str1);
        var splitter2 = splitString(str2);
        while (true) {
            var first = splitter1.next();
            var second = splitter2.next();
            if (null !== first && null !== second) {
                if (xor(first.IsNumber, second.IsNumber)) {
                    return first.IsNumber ? -1 : 1;       
                } else {                   
                    var comp = compare(first.Value, second.Value);   
                    if (comp != 0) {
                        return comp;
                    }
                }
            } else {
                return compare(splitter1.count(), splitter2.count());
            }
        }
    }
    var arr = stringArray;
    return arr.sort(compareStrings); 
}

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";   album_2 = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );
    album = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );
   
    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_text_array();
    } else{
        get_lastFM_a_text(album, a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");

                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML);
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function search_lastFM_album_img(){
    if (!metadb) return; 
    var tf_album = Eval("%album%");
    var tmp_album;
    var tmp_artist = artist;

    if (tf_album){
        tmp_album = input_box("Search album image for", tf_album, "Foobar 2000");

        if (tmp_album) get_lastFM_albums_pages(tmp_album, tmp_artist);
    }
}

function get_lastFM_albums_pages(tmp_album, tmp_artist){
    xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");   
    url0 = ("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(tmp_artist) + "/" + "+albums");
    xmlhttp0.open("GET", url0, true ); 
    xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp0.send(null);     
    xmlhttp0.onreadystatechange = function () {
        if (xmlhttp0.readyState == 4) {
            if (xmlhttp0.status == 200) { 
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp0.responsetext;
                var data = div.getElementsByTagName("li");
                var albums_pages = 0;   
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "pages"){
                        albums_pages = data[i].innerHTML.replace(/^\s+|\s+$/g,"").replace(/^(.*\s)/g,'');
                    }
                }
            }     
            doc.close();
            albums_pages = albums_pages == 0 ? 1 : albums_pages;
            for (i = 1; i <= albums_pages; i++) { 
                get_lastFM_album_img(i, tmp_album, tmp_artist);
            }
        }
    }
}     

function get_lastFM_album_img(i, tmp_album, tmp_artist){
    var xmlhttp3  = new ActiveXObject("Microsoft.XMLHTTP");   
    var url3 = ("https://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(tmp_artist) + "/" + "+albums" + "?page=" + i); 
    xmlhttp3.open("GET", url3, true ); 
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);     
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var files = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "album-grid-album-art"){ 
                        if ((data[i].src.indexOf("https://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            if (data[i].alt.replace(/^(.*?)'|'$/g,'').replace(/\s/,'').toLowerCase() == tmp_album.replace(/\s/,'').toLowerCase()){
                                urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                                files.push(clean_name(tmp_artist) + "_" + clean_name(tmp_album) + "_" + i + ".jpg");
                            }
                        }     
                    }
                }
                doc.close();
                for (i = 0; i < urls.length; i++) { 
                    save_lastFM_album_img(files[i], urls[i]);
                }
            }
        }
    }     
}

function save_lastFM_album_img(file_name, url){
    var destination_path;
    var tmp_directory_path;

    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + "tmp_lastFM_img\\";
    } else {
        tmp_directory_path = directory_path + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Save  " + nl + nl + file_name + nl + "file to";
    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");
   
    if (string){
        destination_path = folder_exists(string);
       
        if(fso.FolderExists(destination_path)) {
            var file_path = "\"" + destination_path + "\\" + file_name + "\"";
            WshShell.Run(vbs + " " + url + " " + file_path, 0, false);
        }else{
            save_lastFM_album_img(file_name, url);
        }
    }
}

var f_info = window.GetProperty(" file info", false);

function file_info(){
    var img_w, img_h, img_name, img_dim;
    if (files[selected]){
        img_name = "\n\n" + get_fnext(files[selected]);
        img_w = gdi.Image(files[selected]).width;
        img_h = gdi.Image(files[selected]).Height;
        img_dim = "\n" + img_w + " x " + img_h;
        return img_name + img_dim;
    } else {
        return "";
    }
}

function draw_file_info(gr){   
    txt_shadow && gr.GdiDrawText( file_info(), gdi.Font("Arial",12, 0), RGB(0,0,0), 0 + 1, txt_y_cycle + 2, ww, wh, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX);
    gr.GdiDrawText( file_info(), gdi.Font("Arial",12, 0), h_color, 0, txt_y_cycle, ww, wh, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX);
}

var txt_hiden = window.GetProperty("txt hiden", false);

function hide_text(x,y){ 
    window.SetProperty("tmp_txt_x", txt_x);
    window.SetProperty("tmp_txt_y", txt_y);
   
    txt_x = ww - t_margin * 2 - h1_char_width;
    txt_y = wh - (h1_text_row_height + t_margin);
    get_text_array();
}

function restore_text(){ 
    txt_x = window.GetProperty("tmp_txt_x");
    txt_y = window.GetProperty("tmp_txt_y");
    get_text_array();
}

function on_mouse_mbtn_dblclk (x,y){
//function on_mouse_mbtn_down (x,y){
    if (on_header){
        !txt_hiden && hide_text(x,y);
        txt_hiden && restore_text();
        txt_hiden = !txt_hiden;
        window.SetProperty("txt hiden", txt_hiden);
       
        window.SetProperty("txt_x", txt_x);
        window.SetProperty("txt_y", txt_y);
    }
}
kgena_ua
16.02.2017, 21:41
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua:если значения прописаны, то они отображаются.
Да, всё отображается, я с цветами не разобрался и со слепу бледных звёзд не видел. Теперь о моей DUI сборке - закончил и выкладываю пока здесь, - раз есть у людей желание, но есть вопросы, которые , может быть, решаться. Сборка показывает все картинки в файле трека, все веб-картинки (арт/альбом) и ноковер. Чтобы пояснить чего хочу - расскажу как возникла идея. Началось с того, что я захотел, чтобы скрипт "Biography Picture. www.last.fm" показывал только то, что интересно мне (картинки по выбору Арт/Альбом) и был "полегче" - т.е. я вычищал из него строки , где "текст" и на каком-то этапе обнаружил, чтол он стал начинать показ картинок позже оригинала. Поскольку я не программер, то найти это место, которое я зацепил для меня сложно и я придумал такой ход - агрегатировал два окна рядом, одно над другим "Biography Picture. www.last.fm" и "Get Covers (Artwork) && radio logos". "Ведущий скрипт - Biography, когда найдены картинки - он разворачивается на размер всего окна, закрывая Artwork, а когда их нет - "схлопывается" до 3пикселей высоты, открывая Artwork. В Artwork выбрал цикл 5 сек (чтобы успел показать свои картинки до того, как "включится" Biography Picture. Всё работает. Даже если нет сети - показывает (Artwork), а с сетью он успевает показать несколько картинок и сменяется Biography Picture. Всё это зрительно в одном окне.
Что я хочу - чтобы Biography Picture "разворачивалась" не когда скачает картинки, а ещё + к этому - когда Artworkпокажет ВСЕ свои картинки по одному кругу. Для этого нужно передать инфу между скриптами, чего я не умею. Вот об этой помощи и прошу.
Сама сборка вот: http://sendfile.su/1321083
San_dr
25.03.2017, 19:00
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua, seriousstas, с новым годом и с наступающим Рождеством Христовым!
Буду отвечать без цитат. Эту тему пора уже закрывать)))
kgena_ua, это мы ещё обсуждали с самых первых версий БИО. Вспомните ,я тогда писал про включение Grab Focus и т.д. и т.п.(это обсуждение есть в теме, не буду искать сейчас). И никто не спорит что текст увеличивался при зажатой кнопке Shift, но не совсем правильно как по мне, о чём написал в предыдущих сообщениях. Что такое "Клацать шифтом" ? Тут всё просто: Вы пробовали сразу за один присест увеличить шрифт от 16 до 96(мой вариант)? Уверен что нет! Так у вас этот зазор (по умолчанию) 16 - 12 = 4. И при такой регулировке подобные артефакты конечно не заметны! Поэтому высказал свою идею о разделении функций, а сам уже давно эту проблему решил. Об этом ниже.
seriousstas, ну опять))) Я же тебя не заставляю что-то там исправлять! Сам это заметил когда специально твой мод включил(нужны были подсказки) Раньше тоже не замечал (когда тестировал), так как кнопками всё делал как и ты (так удобнее)!
Вынудили меня в четыре утра скриншоты делать и сообщения писать))) Сейчас устаю сильно, помогаю дочке с проектом в Unity, приходится вспоминать то что уже не только забыл, но и не знал совсем. Вчера в Skype конференции больше восьми часов - это для меня очень тяжело.

Выкладываю вашу Biography Text && Picture. www.last.fm by kgena_ua от "14112016" в моей редакции для всех(DUI & CUI & всё остальное)
Изображение
Код: Выделить всё
Что добавил:
1. Авто компенсация жирного шрифта при увеличении.
2. Авто отключение теней на тексте в зависимости от фона. По умолчанию цвет тени равен цвету фона.
3. Для WSH Panel Mod v1.5.6 отключение из меню свойства пункта контекстного меню "Reload"
4. Увеличение шрифта с шагом 1: минимальный 11, максимальный 48. Если настроить то можно получить замену шрифта "BIO" на "Artist" при увеличении.
5. Всякие мелочи (уже не помню) для удобства.
Установка: 1. В настройках WSH Panel Mod: Menu\File\Preferences\Tools\WSH Panel Mod --> Safe Mode Снять галочку!
2. В окне Configure...: Grab Focus включён(стоит галочка)

Управление: Левая кнопка мыши - зажата на тексте: Перетаскивание текста по экрану.

Левая кнопка мыши - двойной щелчок на тексте: Смена языка вывода текста RU / EN

Левая кнопка мыши - двойной щелчок на картинке: Смена изображений Артист/ Альбом

Зажатая клавиша Ctrl + колесо мыши на картинке: Установка/Отключение интервала показа картинок в секундах

Зажатая клавиша Shift + колесо мыши на тексте: Изменение размера отображаемого текста

Колесо мыши на картинке, если нет изображения, меняет логотип last.fm (появятся после первой перезагрузки плеера)

Правая кнопка мыши выбор из контекстного меню:

Заголовок "Артист" Включение / Отключение: "Artist header"

Смена языка вывода текста RU / EN: "en text" ; "ru text"

Показ картинок проигрываемый трек / выбранный трек: "Prefer now playing" ; "Follow selected track"

Отображение обложек Артист / Альбом: "Artist pictures" ; "Albums pictures"

Переход на страницу артиста LAST.FM: "last.fm Artist"

Включение эффекта затухания при смене картинок: "Fade effect"

Пропорции картинок: Align : "adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch"

Количество загружаемых картинок: Download limit: 0 - без картинок; 1, 2, 3, 4, 5, 10, 15, 20 - лимит загрузки;

Качество загружаемых картинок: Download quality: Low - 170x170; Medium - 300x300; High - 500x500; Original - 770x0;

Копировать в папку с файлом: "Copy to folder containing track..."

Открытие программы показа картинок по умолчанию: "Open image"

Сохранять текст и картинки: "Save images and text"

Перезагрузить скрипт: "Reload"


Меню Properties: download limit: настройка лимита загружаемых изображений. По умолчанию 5

scrollbar: false/ true Включение/ Отключение полосы прокрутки

scrollbar width: Ширина полосы прокрутки. По умолчанию 6

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua ""modified AHAPXICT for all"""
// @version "14112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800;

var ww = 200, wh = 200;

var a_header = window.GetProperty(" artist header: on/off", true);
var menu_reload = window.GetProperty("reload (context menu): on/off", true);
var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 11;
var max_font_size = 48;

var a_font, b_font;
get_font();

function get_font(){
var font_name_c = font_name_b;
    font_name_c = font_size_b > 48 ? font_name_a : font_name_b;       // Auto Change: Font Name VS Font Size
var c_font_style = b_font_style;
    if (b_font_style == 1){c_font_style = font_size_b > 17 ? 0 : 1;}  // Auto Change: Font Style VS Font Size
    if (a_header){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
   } else{
    a_font = gdi.Font(font_name_a, font_size_b - font_size_b / 2 - 1, a_font_style);
   }
    b_font = gdi.Font(font_name_c, font_size_b, c_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        a_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
        b_color = window.GetColorCUI(ColorTypeCUI.text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        a_color = window.GetColorDUI(ColorTypeDUI.highlight);
        b_color = window.GetColorDUI(ColorTypeDUI.text);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\tmp_Biography\\_download\\last_fm_logo.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 255);
var default_logo = window.GetProperty(" default last.fm logo (0-5) 6-off", 1);
load_last_fm_logo();

var l_arr = [];
l_arr[0] = gdi.Image(script_path + "Lastfm_logo.png");
l_arr[1] = gdi.Image(script_path + "Lastfm_logo.png");
l_arr[2] = gdi.Image(script_path + "last_fm_logo.png");
l_arr[3] = gdi.Image(script_path + "last_fm_logo.png");
l_arr[4] = gdi.Image(script_path + "logo_static.png");
l_arr[5] = gdi.Image(script_path + "footer_logo.png");

var logo_img = l_arr[default_logo];

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\\|:]/g, "-").replace(/\*/g, "x").replace(/"/g, "''").replace(/[<>]/g, "_").replace(/\?/g, "").replace(/^\./, "_").replace(/\.+$/, "").substr(0,50);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" ------------ User Settings ------------ ", "");
if (window.GetProperty(" ------------ User Settings ------------ ") != "" ) window.SetProperty(" ------------ User Settings ------------ ", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 1);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "500x500" , "600x600"],
    [ "original", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 6);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 220);
var t_margin = window.GetProperty(" margin: text", 5);
var txt_x = window.GetProperty("txt_x", 0); //window.Width / 2
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Width); //window.Height / 2
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("en", "ru");
var lang = window.GetProperty("lang", 1);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("AUTO CYCLE:   " + txt_cycle, b_font, a_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    if(a_header){
    gr.GdiDrawText( tf_artist, a_font, bgcolor, a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( tf_artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    } else{
    gr.GdiDrawText( "||||", a_font, bgcolor, a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_CENTER );   
    gr.GdiDrawText( "||||", a_font, b_color, a_x, a_y, ww - a_x - t_margin, wh, DT_CENTER );   
    }
   
    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
        if (b_color > bgcolor) {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, bgcolor, b_x + 1, b_y + b_text_row_height * i / 2 - 11, ww, wh, DT_LEFT | DT_NOPREFIX );
        }
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 - 12 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        var w, h, x, y;
        var logo_angle = 0;
        var l_margin = ww / 8;
       
        if (default_logo == 0){logo_angle = 320};
        if (ww <= wh && logo_angle > 0 || default_logo == 2){l_margin = 0
        }else if (default_logo == 3){l_margin = ww / 2};
       
        if (logo_img.Width || logo_img.Height) {
        var logo_scale = Math.min((ww - p_margin * 2 - l_margin) / logo_img.Width, (wh - p_margin * 2) / logo_img.Height);
         w = logo_img.Width * logo_scale;
         h = logo_img.Height * logo_scale;
         x = (ww - w) / 2;
      if(ww < wh){
        if(default_logo < 2){
            y = h + p_margin;
        } else if(default_logo == 2){
            y = 0 + p_margin;
        } else if(default_logo == 3){
            y = wh / 3 * logo_scale  + p_margin;
        }
        } else {
            if(default_logo == 0 || default_logo == 3){
            w = logo_img.Width * logo_scale / (ww/wh);
         h = logo_img.Height * logo_scale / (ww/wh);
        }
            x = (ww - w) / 2;
            y = (wh - h) / 3.5;
       }
    }

          if (default_logo < 2){
            gr.DrawImage(logo_img, x, y, w, h, 0, 0, logo_img.Width, logo_img.Height, logo_angle, 85); // 709px-Lastfm_logo.svg.png
        } else if (default_logo < 4){
            gr.DrawImage(logo_img, x, y, w, h, 0, 0, logo_img.Width, logo_img.Height, 0, 150); // Last_fm_logo.png 512x512
        } else if (default_logo == 4){
            gr.DrawImage(logo_img, p_margin + 1, p_margin + 1, logo_img.Width * 0.9, logo_img.Height * 0.9, 0, 0, logo_img.Width, logo_img.Height, 0, 255);  // logo_static.png
        } else if (default_logo == 5){
            gr.DrawImage(logo_img, p_margin + 10, p_margin + 12, logo_img.Width, logo_img.Height, 0, 0, logo_img.Width, logo_img.Height, 0, 120); // footer_logo.png
        }

}

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) + b_text_row_height : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(20, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
    b_scrollbar_h = b_text_rows > b_text_visable_rows ? 1 : 0;

//    sb_x = ww - t_margin - scrollbar_w;
    sb_x = ww - scrollbar_w;

    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
    bg_color = RGBA(getRed(b_color), getGreen(b_color), getBlue(b_color), sb_t/2);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y, scrollbar_w, (wh - b_y - 1) * b_scrollbar_h, bg_color);
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);

/*
    sb_t = on_sb || on_sb_down ? 220 : 120;
   
    scrollbar && gr.FillSolidRect(sb_x, b_y, scrollbar_w, (wh - b_y - 1)*b_scrollbar_h, RGBA(63, 100, 127, sb_t/4));
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, RGBA(63, 100, 127, sb_t));
*/
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return;
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist); tf_artist = Eval("%artist%")} else {artist = ""; tf_artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true );
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) {
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_text_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
}

function get_text() {
    clear_text_var();
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = scrollbar ? Math.max(ww - b_x - t_margin - scrollbar_w - 2, 0) : Math.max(ww - b_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    _menu.AppendMenuItem(MF_ENABLED, 1, "Artist header");
    _menu.CheckMenuItem(1, a_header);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download limit : " + limit);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "0");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "1");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "2");
    _secondgroup.AppendMenuItem(MF_ENABLED, 33, "3");
    _secondgroup.AppendMenuItem(MF_ENABLED, 34, "4");
    _secondgroup.AppendMenuItem(MF_ENABLED, 35, "5");
    _secondgroup.AppendMenuItem(MF_ENABLED, 40, "10");
    _secondgroup.AppendMenuItem(MF_ENABLED, 45, "15");
    _secondgroup.AppendMenuItem(MF_ENABLED, 50, "20");
    _secondgroup.CheckMenuRadioItem(30, 50, limit + 30);
    _secondgroup.EnableMenuItem(limit + 30, 1);

    _thirdgroup = window.CreatePopupMenu();
    _thirdgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _thirdgroup.AppendMenuItem(MF_ENABLED, 60, "Low");
    _thirdgroup.AppendMenuItem(MF_ENABLED, 61, "Medium");
    _thirdgroup.AppendMenuItem(MF_ENABLED, 62, "High");
    _thirdgroup.AppendMenuItem(MF_ENABLED, 63, "Original");
    _thirdgroup.CheckMenuRadioItem(60, 63, download_quality + 60);
    _thirdgroup.EnableMenuItem(download_quality + 60, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 70, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 80, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 90, "Save images and text");
    _menu.CheckMenuItem(90, save_images);

    if (menu_reload){
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    }
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        window.SetProperty(" artist header: on/off", !a_header);
        a_header = window.GetProperty(" artist header: on/off");
        get_font();
        get_text();
        window.Repaint();
        break;
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:
    case 33:
    case 34:
    case 35:
    case 40:
    case 45:
    case 50:
        limit = ret - 30;
        window.SetProperty(" download limit", limit);
        del_folders();
        delay_timer = window.SetTimeout(function () {
        window.ClearTimeout(delay_timer);
        get_pic();
        old_artist = artist;
        step = 0;
        window.Repaint();
        }, 3000);
        break;
    case 60:
    case 61:
    case 62:
    case 63:
        download_quality = ret - 60;
        window.SetProperty("download quality", download_quality);
        del_folders();
        delay_timer = window.SetTimeout(function () {
        window.ClearTimeout(delay_timer);
        get_pic();
        old_artist = artist;
        step = 0;
        window.Repaint();
        }, 3000);       
        break;   
    case 70:
        copy_files();
        break;
    case 80:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 90:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer);
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 17){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "logo_static.png")) {
       
        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);   

        var url = "http://vignette3.wikia.nocookie.net/logopedia/images/1/1d/Last_fm_logo.png/revision/latest?cb=20130411230808"
        var file = "\"" + script_path + "Last_fm_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
               
        var url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/Lastfm_logo.svg/709px-Lastfm_logo.svg.png"
        var file = "\"" + script_path + "Lastfm_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://www.last.fm/static/images/logo_static.png?5b6b42188c40"
        var file = "\"" + script_path + "logo_static.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - (a_text_row_height + t_margin * 2) ? ww - (a_text_row_height + t_margin * 2) : txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
    CtrlDown = utils.IsKeyPressed(0x11) ? true : false;
   
    if (on_pic && !CtrlDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    } else if (logo_img && images.length == 0 && !default_img){
        if (delta < 0) {default_logo = default_logo <= 0 ? 0 : default_logo - 1;};
        if (delta > 0) {default_logo = default_logo >= 5 ? 5 : default_logo + 1;};
        window.SetProperty(" default last.fm logo (0-5) 6-off", default_logo);
        logo_img = l_arr[default_logo];
        window.Repaint();
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 1;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 1;};
        window.SetProperty(" font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - (a_text_row_height + t_margin * 2) && txt_x >= 0 ? ww - (a_text_row_height + t_margin * 2) : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust     
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top     
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch     
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}
AHAPXICT
05.01.2017, 07:32
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 4

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text & Album Info & Picture. www.last.fm
version "16122016"


Мелкие изменения.
Доделан пункт меню Load album image.
Пожалуй все.

Безымянный.jpg
Безымянный2.png

Безымянный3.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "16122016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_h = window.GetProperty(" font name: artist", "Arial");
var font_name_t = window.GetProperty(" font name: biography", "Arial");
var font_size_h = window.GetProperty("font size: artist", 12);
var font_size_t = window.GetProperty("font size: biography", 12);
var h_font_style = window.GetProperty(" font style: artist", 1);
var t_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;
var txt_shadow = window.GetProperty(" shadow of the text", true);

var h_font, t_font;
get_font();

function get_font(){
    h_font = gdi.Font(font_name_h, font_size_h, h_font_style);
    h2_font = gdi.Font(font_name_t, font_size_t, h_font_style);
    t_font = gdi.Font(font_name_t, font_size_t, t_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        h_color = window.GetColorCUI(ColorTypeCUI.text);
        t_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        h_color = window.GetColorDUI(ColorTypeDUI.text);
        t_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, tf_artist, old_artist, album;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    if (!n) return;
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

function get_fn(p) {
    if (!p) return;
    return p.replace(/.*\\|\.[^.]+$/g,'')
}

function get_fnext(p) {
    if (!p) return;
    return p.replace(/.*\\/g,'');
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 1);
var selected = 0;
var files = [];
var images = [];
var test_found = 0;
var save_images = window.GetProperty("save images", true);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var st_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var st_color;

var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var h_x, h1_y, h2_y, t_x, t_x;
var text = "";
var text_not_found = new Array(". . .", ". . .", ". . .");
var s_text = 0;
var h_text_row_height = 0;
var text_row_height = 0;
var text_rows = 0;
var text_visable_rows = 0;
var text_visable_height = 0;
var text_array = [];
var on_text = false;
var on_header = false;
var on_text_down = false;
var refresh_txt = true;

var album_info = window.GetProperty("album info", true);

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");

var lang_query = new Array("", "ru/", "zh/");
var lang_text = new Array("in", "ru", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("artist/album", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();


function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, t_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    txt_shadow && gr.GdiDrawText( tf_artist, h_font, RGB(0,0,0), h_x + 1, h1_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( tf_artist, h_font, h_color, h_x, h1_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    if (album_info && select_p_a == 1){
        txt_shadow && gr.GdiDrawText( album, h2_font, RGB(0,0,0), h_x + 1, h2_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
        gr.GdiDrawText( album, h2_font, t_color, h_x, h2_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    }

    for (var i = 0; i < text_visable_rows * 2; i += 2) {
        try {
            txt_shadow && gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, RGB(0,0,0), t_x + 1, t_y + text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, t_color, t_x, t_y + text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), t_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), t_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "found " + test_found, gdi.Font("Arial",12, 0), t_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "selected " + selected, gdi.Font("Arial",12, 0), t_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
       
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 1, logo_img.Height * 1, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = text_rows > text_visable_rows ? text_visable_height * (text_visable_rows / text_rows) : 0;
    if (text_rows > text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    st_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    st_color = RGBA(getRed(h_color), getGreen(h_color), getBlue(h_color), sb_t);
   
    scrollbar && gr.FillSolidRect(st_x, t_y + scrollbar_y, scrollbar_w, scrollbar_h, st_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist); tf_artist = Eval("%artist%")} else {artist = ""; tf_artist = ""};
    if (artist != old_artist){
        check_folder(artist_folder_path(artist));
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    test_found = 0;
    window.Repaint();
   
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    var url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]+ "?page=" + 1); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var an = div.getElementsByTagName("p");
                var urls = [];
                var name = [];      // album name
                var name2 = [];     // album name
                var name3_tmp = []; // release date
                var name3 = [];     // release date
                var img_exist = [];
 
                if (select_p_a == 1){ 
                    for (i = 0; i < an.length; i++) {   
                        if (an[i].className == "album-grid-item-main-text" ){ 
                            name2.push(an[i].innerHTML.replace(/(&amp;)/g,'&'));
                        }
                    } 

                    for (i = 0; i < an.length; i++) {   
                        if (an[i].className == "album-grid-item-aux-text" ){
                            name3_tmp.push(an[i].innerHTML.replace(/\,/g,''));
                        }
                    }
                   
                    for (i = 0; i < name3_tmp.length; i++) {   
                        if (i%2 != 0) {                           
                            name3.push(name3_tmp[i].replace(/^\s+|\s+$/g,'').replace(/^(.*)\s/g,''));
                        }
                    }
                   
                    if (name3) utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album-grid-item-aux-text", "name3", name3);
                }

                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {   
                            //urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                            //name.push(data[i].alt.replace(/^(.*)'.*$/g,'$1').replace(/^(.*?)'/g,''));
                            if (data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) { 
                                urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                                name.push(data[i].alt.replace(/^(.*)'.*$/g,'$1').replace(/^(.*?)'/g,''));
                                img_exist.push(i - 3);
                            }
                        } 
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "img_exist", "img_exist", img_exist);
                    }
                }

                var found = urls.length;
                test_found = found;
               
                for (i = 0; i < Math.min(urls.length, limit); i++) { 
                    if (select_p_a == 0){                   
                        var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                        WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                    }

                    if (select_p_a == 1){
                        //utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i]);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name2[img_exist[i]]);
                        var file2 = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";   
                        WshShell.Run(vbs + " " + urls[i] + " " + file2, 0, false);
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
                get_text();
            }
        }
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();

    if (files.length > images.length){
        images = [];
        files = naturalSort(files);
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;

    var scale_w = (ww - p_margin * 2) / img.Width;
    var scale_h = (wh - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function clear_txt_var() {
    album = "";
    s_text = 0;
    text = "";
    text_array = [];
    get_text_array();
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";

    if (fso.FolderExists(artist_folder_path(artist))){
        if (fso.FileExists(b_text_file)){
            text = utils.ReadTextFile(b_text_file);
            get_text_array();
        } else{
            get_lastFM_b_text(b_text_file);
        }
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_text_array() {
    h_x = txt_x + t_margin;
    h1_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    h_text_row_height = temp_gr.CalcTextHeight("Text", h_font);
    text_row_height = temp_gr.CalcTextHeight("Text", t_font);
   
    h2_y = h1_y + h_text_row_height;
   
    t_x = txt_x + t_margin;
    t_y = (album_info && select_p_a == 1 ? h2_y + h_text_row_height : h1_y + h_text_row_height) + text_row_height;
   
    string_width = scrollbar ? Math.max(ww - t_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - t_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        text_array = [];
        if (text) text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), t_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    text_rows = text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - t_y));
    text_visable_rows = Math.floor(b_text_visable_area / text_row_height);
    text_visable_height = text_visable_rows * text_row_height;


    if (text_visable_rows + s_text > text_rows && s_text > 0) {
        s_text = (text_rows - text_visable_rows);
    }

    scrollbar_k = text_visable_height / text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    if (fso.FolderExists(artist_folder_path(artist))){
        try {
            file = fso.OpenTextFile( p, 2, true, -1)
            file.WriteLine(t);
            file.Close();
        } catch(e) {
            return;
        }
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 12, lang_text[2] + " text");   
    _menu.CheckMenuRadioItem(10, 12, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 20, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 21, "Follow selected track");   
    _menu.CheckMenuRadioItem(20, 21 , selection_mode + 20);   
    _menu.EnableMenuItem(selection_mode + 20, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 30, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 31, "Albums pictures");   
    _menu.CheckMenuRadioItem(30, 31 , select_p_a + 30);   
    _menu.EnableMenuItem(select_p_a + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 40, "Album info");
    _menu.CheckMenuItem(40, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 50, "last.fm Artist");
    _menu.AppendMenuItem(IS_ARTIST, 51, "last.fm Albums");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Fade effect");
    _menu.CheckMenuItem(60, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 70, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 71, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 72, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 73, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 74, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 75, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(70, 75, align_mode + 70);
    _firstgroup.EnableMenuItem(align_mode + 70, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 80, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 81, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 82, "High");
    _secondgroup.CheckMenuRadioItem(80, 82, download_quality + 80);
    _secondgroup.EnableMenuItem(download_quality + 80, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _thirdgroup = window.CreatePopupMenu();
   
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _thirdgroup.AppendTo(_menu,MF_STRING,  "Copy to folder containing track...");
   
    _thirdgroup.AppendMenuItem(MF_STRING, 90, "Copy file");
    _thirdgroup.AppendMenuItem(MF_STRING, 91, "Copy files");
   
    _menu.AppendMenuItem(MF_STRING, 100, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Save images and text");
    _menu.CheckMenuItem(110, save_images);
   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 120, "Load album image");

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 500, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 510, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 520, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
    case 12:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 20:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 21:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 30:
        select_p_a = 0;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 31:
        select_p_a = 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 40:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 50:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 51:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + "+albums");
        break;
    case 60:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 70:
    case 71:
    case 72:
    case 73:
    case 74:
    case 75:
        align_mode = ret - 70;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 80:
    case 81:
    case 82:   
        download_quality = ret - 80;
        window.SetProperty("download quality", download_quality);
        break;
    case 90:
        select_file = 0;
        copy_files();
        break;
    case 91:
        select_file = 1;
        copy_files();
        break;
    case 100:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 110:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 120:
        search_lastFM_album_img();
        break;
    case 500:
        window.Reload();
        break;
    case 510:
        window.ShowProperties();
        break;   
    case 520:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        for (var i = 0; i < files.length; i += 1) {
            if (get_fn(files[i]).replace(/^(.*?)_|_.*/g,'') == 0 && images.length > 0) {
                next_image(0);
                window.ClearInterval(timer);
             }                 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_header = x >= txt_x && x < st_x && y >= h1_y && y < t_y ? true : false;
    on_text = x >= txt_x && x < st_x && y >= t_y ? true : false;
    on_sb =  x >= st_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_header && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (h_text_row_height + t_margin * 1) ? wh - (h_text_row_height + t_margin * 1) : txt_y;

        get_text_array();
    }

    if (on_sb_down && scrollbar && text_rows > text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (text_rows - text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : text_rows - text_visable_rows : 0;
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(st_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if ((on_header || on_text) && !ShiftDown){
        if (text_rows > text_visable_rows){
            if (delta < 0) {s_text = text_rows - s_text <= text_visable_rows ? text_rows - text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if ((on_header || on_text) && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (on_header && delta < 0) {font_size_h = font_size_h <= min_font_size ? min_font_size : font_size_h - 2;};
        if (on_header && delta > 0) {font_size_h = font_size_h >= max_font_size ? max_font_size : font_size_h + 2;};
        window.SetProperty("font size: artist", font_size_h);
        if (on_text && delta < 0) {font_size_t = font_size_t <= min_font_size ? min_font_size : font_size_t - 2;};
        if (on_text && delta > 0) {font_size_t = font_size_t >= max_font_size ? max_font_size : font_size_t + 2;};
        window.SetProperty("font size: biography", font_size_t);
        get_font();
        refresh_txt = true;
        get_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_header || on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (h_text_row_height + t_margin * 1) && txt_y >= 0 ? wh - (h_text_row_height + t_margin * 1) : txt_y;
   
    refresh_txt = true;
    get_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

var select_file = 0;

function copy_files(){
    var destination_path;
    var tmp_files = [];
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;

    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + "tmp_lastFM_img\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";

    if (select_file == 0){
        files = naturalSort(files);
        tmp_files.push(files[selected]);
        var input_box_text = "Copy  " + nl + nl + get_fnext(tmp_files[0]) + nl + "file to";
    } else {
        tmp_files = files;
        var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";
    }

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");
   
    if (string){
        destination_path = folder_exists(string);
       
        if(fso.FolderExists(destination_path)) {
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }else{
            copy_files();
        }
    }
}

function copy_files_to_folder(p, f, pa){
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

function naturalSort(stringArray) {
    var xor = function(a, b) {
        return a ? !b : b;
    }
    var isDigit = function(chr) {
        var charCode = function(ch) {
            return ch.charCodeAt(0);
        };
        var code = charCode(chr);
        return (code >= charCode('0')) && (code <= charCode('9'));
    }
    var splitString = function(str) {
        var from = 0;   
        var index = 0;
        var count = 0; 
        var splitter = {};

        splitter.count = function () {
            return count;
        }
        splitter.next = function() {
            if (index === str.length) {
                return null;
            }
            while(++index) {
                var currentIsDigit = isDigit(str.charAt(index - 1)); 
                var nextChar = str.charAt(index);
                var currentIsLast = (index === str.length);
                var isBorder = currentIsLast || xor(currentIsDigit, isDigit(nextChar));       
                if (isBorder) {
                var part = str.slice(from, index);
                    from = index;
                    count++;
                    return {
                        IsNumber: currentIsDigit,
                        Value: currentIsDigit ? Number(part) : part
                    }
                }
            }
        }
        return splitter;
    }
    var compareStrings = function(str1, str2) {
        var compare = function(a, b) { 
            return (a < b) ? -1 : (a > b) ? 1 : 0;
        }
        var splitter1 = splitString(str1);
        var splitter2 = splitString(str2);
        while (true) {
            var first = splitter1.next();
            var second = splitter2.next();
            if (null !== first && null !== second) {
                if (xor(first.IsNumber, second.IsNumber)) {
                    return first.IsNumber ? -1 : 1;       
                } else {                   
                    var comp = compare(first.Value, second.Value);   
                    if (comp != 0) {
                        return comp;
                    }
                }
            } else {
                return compare(splitter1.count(), splitter2.count());
            }
        }
    }
    var arr = stringArray;
    return arr.sort(compareStrings); 
}

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";   album_2 = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );
    album = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );
   
    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_text_array();
    } else{
        get_lastFM_a_text(album, a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");

                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////

 
function search_lastFM_album_img(){
    if (!metadb) return; 
    var tf_album = Eval("%album%");
    var tmp_album;
    var tmp_artist = artist;

    if (tf_album){
        tmp_album = input_box("Search album image for", tf_album, "Foobar 2000");

        if (tmp_album) get_lastFM_albums_pages(tmp_album, tmp_artist);
    }
}

function get_lastFM_albums_pages(tmp_album, tmp_artist){
    xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");   
    url0 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(tmp_artist) + "/" + "+albums");
    xmlhttp0.open("GET", url0, true ); 
    xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp0.send(null);     
    xmlhttp0.onreadystatechange = function () {
        if (xmlhttp0.readyState == 4) {
            if (xmlhttp0.status == 200) { 
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp0.responsetext;
                var data = div.getElementsByTagName("li");
                var albums_pages = 0;   
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "pages"){
                        albums_pages = data[i].innerHTML.replace(/^\s+|\s+$/g,"").replace(/^(.*\s)/g,'');
                    }
                }
            }     
            doc.close();
            albums_pages = albums_pages == 0 ? 1 : albums_pages;
            for (i = 1; i <= albums_pages; i++) { 
                get_lastFM_album_img(i, tmp_album, tmp_artist);
            }
        }
    }
}     

function get_lastFM_album_img(i, tmp_album, tmp_artist){
    var xmlhttp3  = new ActiveXObject("Microsoft.XMLHTTP");   
    var url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(tmp_artist) + "/" + "+albums" + "?page=" + i); 
    xmlhttp3.open("GET", url3, true ); 
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);     
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var files = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "album-grid-album-art"){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            if (data[i].alt.replace(/^(.*?)'|'$/g,'').replace(/\s/,'').toLowerCase() == tmp_album.replace(/\s/,'').toLowerCase()){
                                urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                                files.push(clean_name(tmp_artist) + "_" + clean_name(tmp_album) + "_" + i + ".jpg");
                            }
                        }     
                    }
                }
                doc.close();
                for (i = 0; i < urls.length; i++) { 
                    save_lastFM_album_img(files[i], urls[i]);
                }
            }
        }
    }     
}

function save_lastFM_album_img(file_name, url){
    var destination_path;
    var tmp_directory_path;

    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + "tmp_lastFM_img\\";
    } else {
        tmp_directory_path = directory_path + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Save  " + nl + nl + file_name + nl + "file to";
    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");
   
    if (string){
        destination_path = folder_exists(string);
       
        if(fso.FolderExists(destination_path)) {
            var file_path = "\"" + destination_path + "\\" + file_name + "\"";
            WshShell.Run(vbs + " " + url + " " + file_path, 0, false);
        }else{
            save_lastFM_album_img(file_name, url);
        }
    }
}



kgena_ua
16.12.2016, 23:40
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 4

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text & Album Info & Picture. www.last.fm
version "01122016"


- подписи к альбомам теперь в правильном порядке;
- добавлен пункт меню "скопировать файл";
- размер шрифта колесом мыши отдельно для артиста и текста;
- добавлен пункт меню "загрузить обложку выбранного (воспроизводимого) альбома". Грузит в папку tmp_Biography, пункт не тестировал, и вообще, нужно-ли это.

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "01122016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_h = window.GetProperty(" font name: artist", "Arial");
var font_name_t = window.GetProperty(" font name: biography", "Arial");
var font_size_h = window.GetProperty("font size: artist", 12);
var font_size_t = window.GetProperty("font size: biography", 12);
var h_font_style = window.GetProperty(" font style: artist", 1);
var t_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;
var txt_shadow = window.GetProperty(" shadow of the font", true);

var h_font, t_font;
get_font();

function get_font(){
    h_font = gdi.Font(font_name_h, font_size_h, h_font_style);
    h2_font = gdi.Font(font_name_t, font_size_t, h_font_style);
    t_font = gdi.Font(font_name_t, font_size_t, t_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        h_color = window.GetColorCUI(ColorTypeCUI.text);
        t_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        h_color = window.GetColorDUI(ColorTypeDUI.text);
        t_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, tf_artist, old_artist, album;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    if (!n) return;
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    try {
        if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
    } catch(e) {}
}

function get_fn(p) {
    if (!p) return;
    return p.replace(/.*\\|\..*/g,'');
}

function get_fnext(p) {
    if (!p) return;
    return p.replace(/.*\\/g,'');
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 1);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var st_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var st_color;

var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var h_x, h1_y, h2_y, t_x, t_x;
var text = "";
var text_not_found = new Array(". . .", ". . .", ". . .");
var s_text = 0;
var h_text_row_height = 0;
var text_row_height = 0;
var text_rows = 0;
var text_visable_rows = 0;
var text_visable_height = 0;
var text_array = [];
var on_text = false;
var on_header = false;
var on_text_down = false;
var refresh_txt = true;

var album_info = window.GetProperty("album info", true);

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");

//var lang_query = new Array("", "ru/", "zh/");
//var lang_text = new Array("in", "ru", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("artist/album", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();


function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, t_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    txt_shadow && gr.GdiDrawText( tf_artist, h_font, RGB(0,0,0), h_x + 1, h1_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( tf_artist, h_font, h_color, h_x, h1_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    if (album_info && select_p_a == 1){
        txt_shadow && gr.GdiDrawText( album, h2_font, RGB(0,0,0), h_x + 1, h2_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
        gr.GdiDrawText( album, h2_font, t_color, h_x, h2_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    }

    for (var i = 0; i < text_visable_rows * 2; i += 2) {
        try {
            txt_shadow && gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, RGB(0,0,0), t_x + 1, t_y + text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, t_color, t_x, t_y + text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), t_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), t_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( selected, gdi.Font("Arial",12, 0), t_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 80, ww, wh, DT_LEFT | DT_WORDBREAK );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 100, ww, wh, DT_LEFT | DT_WORDBREAK );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 120, ww, wh, DT_LEFT | DT_WORDBREAK );

}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
       
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 1, logo_img.Height * 1, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = text_rows > text_visable_rows ? text_visable_height * (text_visable_rows / text_rows) : 0;
    if (text_rows > text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    st_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    st_color = RGBA(getRed(h_color), getGreen(h_color), getBlue(h_color), sb_t);
   
    scrollbar && gr.FillSolidRect(st_x, t_y + scrollbar_y, scrollbar_w, scrollbar_h, st_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist); tf_artist = Eval("%artist%")} else {artist = ""; tf_artist = ""};
    if (artist != old_artist){
        check_folder(artist_folder_path(artist));
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    var xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    var url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]+ "?page=" + 1); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var an = div.getElementsByTagName("p");
                var urls = [];
                var name = [];
                               
                for (i = 0; i < an.length; i++) {   
                    if (an[i].className == "album-grid-item-main-text" ){ 
                        //name.push(an[i].innerHTML);
                    }
                }               
               
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {   
                        //if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) { 
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]));
                            name.push(data[i].alt.replace(/^(.*)'.*$/g,'$1').replace(/^(.*?)'/g,''));
                        }     
                    }
                }
               
                if (name) utils.WriteINI( p + "\\" + artist + "_album_info.ini", "albums_name", "albums", name);
               
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) { 
                    if (select_p_a == 0){                   
                        var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                        WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                    }

                    if (select_p_a == 1){
                        var file2 = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";   
                        WshShell.Run(vbs + " " + urls[i] + " " + file2, 0, false);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i]);
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();

    if (files.length > images.length){
        images = [];
        files = naturalSort(files);
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;

    var scale_w = (ww - p_margin * 2) / img.Width;
    var scale_h = (wh - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function clear_txt_var() {
    album = "";
    s_text = 0;
    text = "";
    text_array = [];
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";

    if (fso.FolderExists(artist_folder_path(artist))){
        if (fso.FileExists(b_text_file)){
            text = utils.ReadTextFile(b_text_file);
            get_text_array();
        } else{
            get_lastFM_b_text(b_text_file);
        }
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_text_array() {
    h_x = txt_x + t_margin;
    h1_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    h_text_row_height = temp_gr.CalcTextHeight("Text", h_font);
    text_row_height = temp_gr.CalcTextHeight("Text", t_font);
   
    h2_y = h1_y + h_text_row_height;
   
    t_x = txt_x + t_margin;
    t_y = (album_info && select_p_a == 1 ? h2_y + h_text_row_height : h1_y + h_text_row_height) + text_row_height;
   
    string_width = scrollbar ? Math.max(ww - t_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - t_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        text_array = [];
        if (text) text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), t_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    text_rows = text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - t_y));
    text_visable_rows = Math.floor(b_text_visable_area / text_row_height);
    text_visable_height = text_visable_rows * text_row_height;


    if (text_visable_rows + s_text > text_rows && s_text > 0) {
        s_text = (text_rows - text_visable_rows);
    }

    scrollbar_k = text_visable_height / text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    //_menu.AppendMenuItem(MF_ENABLED, 12, lang_text[2] + " text");   
    _menu.CheckMenuRadioItem(10, 12, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 20, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 21, "Follow selected track");   
    _menu.CheckMenuRadioItem(20, 21 , selection_mode + 20);   
    _menu.EnableMenuItem(selection_mode + 20, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 30, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 31, "Albums pictures");   
    _menu.CheckMenuRadioItem(30, 31 , select_p_a + 30);   
    _menu.EnableMenuItem(select_p_a + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 40, "Album info");
    _menu.CheckMenuItem(40, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 50, "last.fm Artist");
    _menu.AppendMenuItem(IS_ARTIST, 51, "last.fm Albums");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Fade effect");
    _menu.CheckMenuItem(60, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 70, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 71, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 72, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 73, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 74, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 75, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(70, 75, align_mode + 70);
    _firstgroup.EnableMenuItem(align_mode + 70, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 80, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 81, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 82, "High");
    _secondgroup.CheckMenuRadioItem(80, 82, download_quality + 80);
    _secondgroup.EnableMenuItem(download_quality + 80, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _thirdgroup = window.CreatePopupMenu();
   
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _thirdgroup.AppendTo(_menu,MF_STRING,  "Copy to folder containing track...");
   
    _thirdgroup.AppendMenuItem(MF_STRING, 90, "Copy file");
    _thirdgroup.AppendMenuItem(MF_STRING, 91, "Copy files");
   
    _menu.AppendMenuItem(MF_STRING, 100, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 110, "Save images and text");
    _menu.CheckMenuItem(110, save_images);
   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 120, "Load album image (in work)");

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 500, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 510, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 520, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
    case 12:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 20:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 21:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 30:
        select_p_a = 0;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 31:
        select_p_a = 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 40:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 50:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 51:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + "+albums");
        break;
    case 60:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 70:
    case 71:
    case 72:
    case 73:
    case 74:
    case 75:
        align_mode = ret - 70;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 80:
    case 81:
    case 82:   
        download_quality = ret - 80;
        window.SetProperty("download quality", download_quality);
        break;
    case 90:
        select_file = 0;
        copy_files();
        break;
    case 91:
        select_file = 1;
        copy_files();
        break;
    case 100:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 110:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 120:
        search_lastFM_album_img();
        break;
    case 500:
        window.Reload();
        break;
    case 510:
        window.ShowProperties();
        break;   
    case 520:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        for (var i = 0; i < files.length; i += 1) {
            if (get_fn(files[i]).replace(/^(.*?)_|_.*/g,'') == 0 && images.length > 0) {
                next_image(0);
                window.ClearInterval(timer);
                break;
             }                 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_header = x >= txt_x && x < st_x && y >= h1_y && y < t_y ? true : false;
    on_text = x >= txt_x && x < st_x && y >= t_y ? true : false;
    on_sb =  x >= st_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_header && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (h_text_row_height + t_margin * 1) ? wh - (h_text_row_height + t_margin * 1) : txt_y;

        get_text_array();
    }

    if (on_sb_down && scrollbar && text_rows > text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (text_rows - text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : text_rows - text_visable_rows : 0;
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(st_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if ((on_header || on_text) && !ShiftDown){
        if (text_rows > text_visable_rows){
            if (delta < 0) {s_text = text_rows - s_text <= text_visable_rows ? text_rows - text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if ((on_header || on_text) && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (on_header && delta < 0) {font_size_h = font_size_h <= min_font_size ? min_font_size : font_size_h - 2;};
        if (on_header && delta > 0) {font_size_h = font_size_h >= max_font_size ? max_font_size : font_size_h + 2;};
        window.SetProperty("font size: artist", font_size_h);
        if (on_text && delta < 0) {font_size_t = font_size_t <= min_font_size ? min_font_size : font_size_t - 2;};
        if (on_text && delta > 0) {font_size_t = font_size_t >= max_font_size ? max_font_size : font_size_t + 2;};
        window.SetProperty("font size: biography", font_size_t);
        get_font();
        refresh_txt = true;
        get_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_header || on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (h_text_row_height + t_margin * 1) && txt_y >= 0 ? wh - (h_text_row_height + t_margin * 1) : txt_y;
   
    refresh_txt = true;
    get_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

var select_file = 0;

function copy_files(){
    var destination_path;
    var tmp_files = [];
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;

    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";

    if (select_file == 0){
        files = naturalSort(files);
        tmp_files.push(files[selected]);
        var input_box_text = "Copy  " + nl + nl + get_fnext(tmp_files[0]) + nl + "file to";
    } else {
        tmp_files = files;
        var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";
    }

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");
   
    if (string){
        destination_path = folder_exists(string);
       
        if(fso.FolderExists(destination_path)) {
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }else{
            copy_files();
        }
    }
}

function copy_files_to_folder(p, f, pa){
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

function naturalSort(stringArray) {
    var xor = function(a, b) {
        return a ? !b : b;
    }
    var isDigit = function(chr) {
        var charCode = function(ch) {
            return ch.charCodeAt(0);
        };
        var code = charCode(chr);
        return (code >= charCode('0')) && (code <= charCode('9'));
    }
    var splitString = function(str) {
        var from = 0;   
        var index = 0;
        var count = 0; 
        var splitter = {};

        splitter.count = function () {
            return count;
        }
        splitter.next = function() {
            if (index === str.length) {
                return null;
            }
            while(++index) {
                var currentIsDigit = isDigit(str.charAt(index - 1)); 
                var nextChar = str.charAt(index);
                var currentIsLast = (index === str.length);
                var isBorder = currentIsLast || xor(currentIsDigit, isDigit(nextChar));       
                if (isBorder) {
                var part = str.slice(from, index);
                    from = index;
                    count++;
                    return {
                        IsNumber: currentIsDigit,
                        Value: currentIsDigit ? Number(part) : part
                    }
                }
            }
        }
        return splitter;
    }
    var compareStrings = function(str1, str2) {
        var compare = function(a, b) { 
            return (a < b) ? -1 : (a > b) ? 1 : 0;
        }
        var splitter1 = splitString(str1);
        var splitter2 = splitString(str2);
        while (true) {
            var first = splitter1.next();
            var second = splitter2.next();
            if (null !== first && null !== second) {
                if (xor(first.IsNumber, second.IsNumber)) {
                    return first.IsNumber ? -1 : 1;       
                } else {                   
                    var comp = compare(first.Value, second.Value);   
                    if (comp != 0) {
                        return comp;
                    }
                }
            } else {
                return compare(splitter1.count(), splitter2.count());
            }
        }
    }
    var arr = stringArray;
    return arr.sort(compareStrings); 
}

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";
    album = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );
   
    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_text_array();
    } else{
        get_lastFM_a_text(album, a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");

                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}



////////////////////////////////////////////////////////////////////////////////////////////////////

var albums_pages;
   
function search_lastFM_album_img(){
    if (!metadb) return; 
    var tf_album = Eval("%album%");
    var string;
   
    if (tf_album){
        string = input_box("Load album image", tf_album, "Foobar 2000");
   
        if (string){
            if (string) get_lastFM_albums_pages(string);
        }
    }
}

function get_lastFM_albums_pages(a){
    xmlhttp0 = new ActiveXObject("Microsoft.XMLHTTP");   
    url0 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + "+albums");
    xmlhttp0.open("GET", url0, true ); 
    xmlhttp0.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp0.send(null);     
    xmlhttp0.onreadystatechange = function () {
        if (xmlhttp0.readyState == 4) {
            if (xmlhttp0.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp0.responsetext;
                var data = div.getElementsByTagName("li");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "pages"){
                        albums_pages = data[i].innerHTML.replace(/^\s+|\s+$/g,"").replace(/^(.*\s)/g,'');
                    }
                }
            }     
            doc.close();
            for (i = 1; i <= albums_pages; i++) { 
                get_lastFM_album(i, a);
            }
        }
    }
}     

function get_lastFM_album(i, a){
    var xmlhttp3  = new ActiveXObject("Microsoft.XMLHTTP");   
    var url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + "+albums" + "?page=" + i); 
    xmlhttp3.open("GET", url3, true ); 
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);     
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "album-grid-album-art"){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            if (data[i].alt.replace(/^(.*?)'|'$/g,'').replace(/\s/,'').toLowerCase() == a.replace(/\s/,'').toLowerCase()){
                                p = tmp_b_path;
                                var url = data[i].src.replace("300x300", quality[download_quality][2]);
                                var file = "\"" + p + "\\" + clean_name(artist) + "_" + clean_name(a) + ".jpg" + "\"";
                                WshShell.Run(vbs + " " + url + " " + file, 0, false);
                            }
                        }     
                    }
                }
                doc.close();
            }
        }
    }     
}



kgena_ua
01.12.2016, 16:42
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

MC Web, тут моя невнимательность. Я просто названия некоторых переменных и функций изменил. Лучше выложу новую версию:

Biography Text & Album Info & Picture. www.last.fm
version "18112016


- добавил отображения названия альбома;
- изменения в меню: last.fm Artist или last.fm Album;
- поддержка CUI и DUI.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "18112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_h = window.GetProperty(" font name: artist", "Arial");
var font_name_t = window.GetProperty(" font name: biography", "Arial");
var font_size_h_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_t = window.GetProperty(" font size: biography", 12);
var h_font_style = window.GetProperty(" font style: artist", 1);
var t_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var h_font, t_font;
get_font();

function get_font(){
    h_font = gdi.Font(font_name_h, font_size_t + font_size_h_d, h_font_style);
    t_font = gdi.Font(font_name_t, font_size_t, t_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

ColorTypeDUI = {
   text: 0,
   background: 1,
   highlight: 2,
   selection: 3
};

function get_color(){   
    if (window.InstanceType == 0){
        bgcolor = window.GetColorCUI(ColorTypeCUI.background);
        h_color = window.GetColorCUI(ColorTypeCUI.text);
        t_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    } else if (window.InstanceType == 1) {
        bgcolor = window.GetColorDUI(ColorTypeDUI.background);
        h_color = window.GetColorDUI(ColorTypeDUI.text);
        t_color = window.GetColorDUI(ColorTypeDUI.highlight);
    }
    window.Repaint();
};

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
//var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist, album;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var st_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var st_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var h_x, h1_y, h2_y, t_x, t_x;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var h_text_row_height = 0;
var text_row_height = 0;
var text_rows = 0;
var text_visable_rows = 0;
var text_visable_height = 0;
var text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var album_info = window.GetProperty("album info", true);

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("artist/album", 0);
//var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, t_font, t_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, h_font, RGB(0,0,0), h_x + 1, h1_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, h_font, h_color, h_x, h1_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    if (album_info && select_p_a == 1){
        gr.GdiDrawText( album, h_font, RGB(0,0,0), h_x + 1, h2_y + 2, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
        gr.GdiDrawText( album, h_font, t_color, h_x, h2_y, ww - h_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    }

    for (var i = 0; i < text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, RGB(0,0,0), t_x + 1, t_y + text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), t_font, t_color, t_x, t_y + text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), t_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), t_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( selected, gdi.Font("Arial",12, 0), t_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 80, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), t_color, 10, 100, ww, wh, DT_LEFT | DT_WORDBREAK );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 1, logo_img.Height * 1, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = text_rows > text_visable_rows ? text_visable_height * (text_visable_rows / text_rows) : 0;
    if (text_rows > text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    st_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    st_color = RGBA(getRed(h_color), getGreen(h_color), getBlue(h_color), sb_t);
   
    scrollbar && gr.FillSolidRect(st_x, t_y + scrollbar_y, scrollbar_w, scrollbar_h, st_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var name = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                            name.push(data[i].alt.replace(/^(.*?)'|'$/g,''));
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                   
                    if (select_p_a == 1){
                        name.push(name[i]);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i]);
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function clear_txt_var() {
    album = "";
    s_text = 0;
    text = "";
    text_array = [];
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    if (fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_text_array() {
    h_x = txt_x + t_margin;
    h1_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    h_text_row_height = temp_gr.CalcTextHeight("Text", h_font);
    text_row_height = temp_gr.CalcTextHeight("Text", t_font);
   
    h2_y = h1_y + h_text_row_height;
   
    t_x = txt_x + t_margin;
    t_y = (album_info && select_p_a == 1 ? h2_y + h_text_row_height : h1_y + h_text_row_height) + text_row_height;
   
    string_width = scrollbar ? Math.max(ww - t_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - t_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        text_array = [];
        if (text) text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), t_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    text_rows = text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - t_y));
    text_visable_rows = Math.floor(b_text_visable_area / text_row_height);
    text_visable_height = text_visable_rows * text_row_height;


    if (text_visable_rows + s_text > text_rows && s_text > 0) {
        s_text = (text_rows - text_visable_rows);
    }

    scrollbar_k = text_visable_height / text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 16, "Album info");
    _menu.CheckMenuItem(16, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
   
    switch (select_p_a){
    case 0:
        IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
        _menu.AppendMenuItem(IS_ARTIST, 17, "last.fm Artist");
        break;
    case 1:
        IS_ALBUM = album ? MF_ENABLED : MF_GRAYED;   
        _menu.AppendMenuItem(IS_ALBUM, 17, "last.fm Album");
        break;
    }
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 18, "Fade effect");
    _menu.CheckMenuItem(18, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
        break;
    case 16:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 17:
        switch (select_p_a){
        case 0:
            WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
            break;
        case 1:
            WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album));
            break;
        }
        break;
    case 18:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_static.png?5b6b42188c40"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < st_x && y  >= txt_y ? true : false;
    on_sb =  x >= st_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (h_text_row_height + t_margin * 1) ? wh - (h_text_row_height + t_margin * 1) : txt_y;

        get_text_array();
    }

    if (on_sb_down && scrollbar && text_rows > text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (text_rows - text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : text_rows - text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(st_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (text_rows > text_visable_rows){
            if (delta < 0) {s_text = text_rows - s_text <= text_visable_rows ? text_rows - text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_t = font_size_t <= min_font_size ? min_font_size : font_size_t - 2;};
        if (delta > 0) {font_size_t = font_size_t >= max_font_size ? max_font_size : font_size_t + 2;};
        window.SetProperty("font size: biography", font_size_t);
        get_font();
        refresh_txt = true;
        get_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("artist/album", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (h_text_row_height + t_margin * 1) && txt_y >= 0 ? wh - (h_text_row_height + t_margin * 1) : txt_y;
   
    refresh_txt = true;
    get_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";
   
    album = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );

    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_text_array();
    } else{
        get_lastFM_a_text(album, a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        if (text != "") save_txt_file(text, p);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = text_not_found[lang];
            get_text_array();
        }
    }
}


kgena_ua
18.11.2016, 13:24
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

И Вам спасибо, AHAPXICT, и всем, кто тестировал, особенно seriousstas и MC Web. Особый привет ximenlangzige.

Т Е С Т

Biography Text & Album Info & Picture. www.last.fm
version "16112016"


Безымянный.png


Добавлен пункт меню Album info для отображения описания альбома при выборе пункта меню Albums pictures (или двойной клик по картинке - переключатель Artist pictures/Albums pictures)

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text & Album Info & Picture. www.last.fm"
// @author "kgena_ua"
// @version "16112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( selected, gdi.Font("Arial",12, 0), b_color, 10, 40, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 60, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 80, ww, wh, DT_LEFT | DT_WORDBREAK );
    //gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 100, ww, wh, DT_LEFT | DT_WORDBREAK );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
        old_artist = artist;
    }
}   

function get_text(){
    if (album_info && select_p_a == 1){
        get_a_text(selected);
    } else {
        get_b_text();
    }
}

function get_pic() {
    clear_txt_var();
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");   
    url1 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]); 
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                var name = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                            name.push(data[i].alt.replace(/^(.*?)'|'$/g,''));
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                   
                    if (select_p_a == 1){
                        name.push(name[i]);
                        utils.WriteINI( p + "\\" + artist + "_album_info.ini", "album_name", i, name[i] );
                    }
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
    if (album_info && select_p_a == 1) get_a_text(selected);
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_txt_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
    window.Repaint();
}

function get_b_text() {
    clear_txt_var();
    refresh_txt = true;
    var b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    if (fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = scrollbar ? Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0) : Math.max(ww - b_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_txt_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 16, "Album info");
    _menu.CheckMenuItem(16, album_info);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 17, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 18, "Fade effect");
    _menu.CheckMenuItem(18, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
    case 11:
        lang = ret - 10;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        window.SetProperty("album info", ! album_info);
        album_info = window.GetProperty("album info");
        get_text();
        break;
    case 17:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 18:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_static.png?5b6b42188c40"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

var album_info = window.GetProperty("album info", true);

function get_a_text(s) {
    clear_txt_var();
    refresh_txt = true;
    var a_text_file = artist_folder_path(artist) + "\\" + artist + "_" + s + "_albums_" + lang_text[lang] + ".txt";
    var album_name = utils.ReadINI( artist_folder_path(artist) + "\\" + artist + "_album_info.ini", "album_name", s );

    if (fso.FileExists(a_text_file)){
        text = utils.ReadTextFile(a_text_file);
        get_b_text_array();
    } else{
        get_lastFM_a_text(album_name,a_text_file);
    }
}

function get_lastFM_a_text(album, p){
    xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
    url3 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/" + encodeURIComponent(album) + "/+wiki");
    xmlhttp3.open("GET", url3, true);
    xmlhttp3.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp3.send(null);
    xmlhttp3.onreadystatechange = function () {
        if (xmlhttp3.readyState == 4) {
            if (xmlhttp3.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp3.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content" && album) {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_txt_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}
kgena_ua
16.11.2016, 12:47
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 3

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version "14112016"


Грузит все, сбоев нет.
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "14112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.,]/g,'').replace(/^\s+|\s+$/g,"").substr(0,200);
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if (!n) return;
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "avatar300s"],
    [ "medium", "300x300" , "300x300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
//var lang_query = new Array("", "zh/");
//var lang_text = new Array("in", "zh");

var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

    //gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
        metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
 //   if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        clear_text_var();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
            get_text();
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true ); 
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){ 
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300x300", quality[download_quality][2]))
                        }     
                    }
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    var file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, 0, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }
        get_text();       
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function clear_text_var() {
    s_text = 0;
    text = "";
    b_text_array = [];
}

function get_text() {
    clear_text_var();
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_text[lang] + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML).replace(/^\s+|\s+$/g,"");
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text.replace(/^\s+|\s+$/g,""), b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, lang_text[0] + " text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, lang_text[1] + " text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(60, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    //case 100:
    //    window.Reload();
    //    break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
        return driver + "\\" + p;
    }
}
/*
function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}
*/
kgena_ua
14.11.2016, 18:09
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400

Re: Скрипты для foo_uie_wsh_panel_mod

WSH Biography Text & Picture Last.fm_rus (10.11.2016)
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "10112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800;

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Verdan");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 4);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 2);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}
*/

var bgcolor = RGB(19,30,38);    // RGB(31,41,48);
var a_color = RGB(128,192,255); // RGB(220,220,220);
var b_color = RGB(192,192,192); // RGB(255,255,230);

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\tmp_Biography\\_download\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 255);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&\.]/g,'').replace(/^\s+|\s+$/g,"");
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("Подогнать", "Подогнать сверху - по центру", "Подогнать сверху - слева", "По центру", "По центру - сверху", "Растянуть");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "низкое", "avatar170s" , "300"],
    [ "среднее", "300x300" , "300"],
    [ "высокое", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array("\n\nНичего не найдено", "\n\nНичего не найдено");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "Отключено" : cycle + " сек.";   
        set_cycle && gr.GdiDrawText("Зацикливание изображений \n" + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_CENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

   // gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return;
//  artist = Eval("%artist%");
    artist = Eval("$upper([%artist%])");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_pic();
//      get_text();   //////////////////////////
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) {
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
//                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){   
//                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
//                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){
                        if ((data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/300") == 0) && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
 //             get_text(); ////////////////////////
            }
        }     
                get_text();
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    b_text_array = [];
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_query[lang].replace(/\//g,'') + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "Английский язык");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "Русский язык");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Предпочитать воспроизводимый");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Следовать за выбранным треком");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 14, "Фото исполнителя");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Обложка альбома");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "Страничка исполнителя на Last.fm");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Эффект плавного перехода");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Выравнивание : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Качество изображения : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Низкое");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Среднее");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "Высокое");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Копировать в папку с треком...");
    _menu.AppendMenuItem(MF_STRING, 50, "Открыть изображение");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Сохранять изображения и текст");
    _menu.CheckMenuItem(40, save_images);

//    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
//    _menu.AppendMenuItem(MF_ENABLED, 100, "Перезагрузить");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Свойства WSH");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Настройки WSH...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
//    case 100:
//        window.Reload();
//        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer);
        }
    }, 500 );   // 500
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );  // 1000
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );  // 1000
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);    // 200
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
   if (ShiftDown) on_key_down();
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust     
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top     
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch     
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Копировать  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "файлы в";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

//var WshShell = WScript.CreateObject("WScript.Shell")
//WshShell.SendKeys("+{F10}");
Сейчас этот вариант у себя гоняю...
MC Web
14.11.2016, 14:34
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version 10112016

Безымянный2.png
Безымянный2.png (11.38 КБ) Просмотров: 3641
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "10112016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

MF_ENABLED = 0x00000000;   
MF_GRAYED = 0x00000001;   
MF_SEPARATOR = 0x00000800; 

var ww = 200, wh = 200;

var font_name_a = window.GetProperty(" font name: artist", "Arial");
var font_name_b = window.GetProperty(" font name: biography", "Arial");
var font_size_a_d = window.GetProperty(" font size: artist (delta)", 0);
var font_size_b = window.GetProperty(" font size: biography", 12);
var a_font_style = window.GetProperty(" font style: artist", 1);
var b_font_style = window.GetProperty(" font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var default_img_path = window.GetProperty(" default img path",".\\maybe\\textures\\nocover\\nocover.png");
var default_img = window.GetProperty(" default img", false);
var default_img_transparent = window.GetProperty(" default img transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "footer_logo.png");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[^a-zA-Z0-9а-яА-Я\s-&]/g,'').replace(/^\s+|\s+$/g,"");
}

function artist_folder_path(n) {
    return tmp_b_path + n;
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

String.prototype.repeat = function(n) {
    return new Array(n + 1).join(this);
}

window.SetProperty(" - user", "");
if (window.GetProperty(" - user") != "" ) window.SetProperty(" - user", "");
window.SetProperty("-".repeat(50), "");
if (window.GetProperty("-".repeat(50)) != "" ) window.SetProperty("-".repeat(50), "");

var g_img = null;
var p_margin = window.GetProperty(" margin: picture", 0);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty(" download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var download_quality = window.GetProperty("download quality", 1);
var quality = [
    [ "low", "avatar170s" , "300"],
    [ "medium", "300x300" , "300"],
    [ "high", "770x0" , ""]
];

var scrollbar = window.GetProperty(" scrollbar", true);
var scrollbar_w = window.GetProperty(" scrollbar width ", 4);
var scrollbar_k;
var sb_x = 0;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;
var sb_color;

var b_file;
var bg_transparent = window.GetProperty(" bg transparent (0-255)", 200);
var t_margin = window.GetProperty(" margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y, b_x, b_y;
var text = "";
var text_not_found = new Array(". . .", ". . .");
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var lang_query = new Array("", "ru/");
var lang_text = new Array("in", "ru");
var lang = window.GetProperty("lang", 0);

var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var panel_on = true;

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
   
    draw_image(gr);

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle:   " + txt_cycle, b_font, b_color, 0, 20, ww, wh, DT_CENTER | DT_WORD_ELLIPSIS );
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),bg_transparent));   
    }   

    draw_scrollbar(gr);   
   
    gr.GdiDrawText( artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText( artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
        try {
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
            gr.GdiDrawText( b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
        } catch(e) {}
    }

   // gr.GdiDrawText( "files " + files.length, gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    //gr.GdiDrawText( "images " + images.length, gdi.Font("Arial",12, 0), b_color, 10, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function draw_image(gr){
    if (g_img && images.length > 0){
        var size = calc_img_size(g_img);
        gr.DrawRect(size.x, size.y, size.width, size.height, 1, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),fader));
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !default_img){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 100);         
    }

    if (images.length == 0 && default_img){
        try {
            nc_img = gdi.Image(default_img_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, default_img_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    sb_x = ww - t_margin - scrollbar_w;
   
    sb_t = on_sb || on_sb_down ? 150 : 50;
    sb_color = RGBA(getRed(a_color), getGreen(a_color), getBlue(a_color), sb_t);
   
    scrollbar && gr.FillSolidRect(sb_x, b_y + scrollbar_y, scrollbar_w, scrollbar_h, sb_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!panel_on) return;
    if (!metadb) return; 
    artist = Eval("%artist%");
    if (artist) {artist = clean_name(artist)} else {artist = ""};
    if (artist != old_artist){
        if (!save_images) del_folders(artist);
        get_text();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    images = [];
    files = [];
    selected = 0;
    g_img = null;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    if (fso.FolderExists(artist_folder_path(artist))){
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) {
            next_image(0);
        } else {
            get_lastFM_pic(artist_folder_path(artist));
        }
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {   
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0 || data[i].src.indexOf("https://lastfm-img2.akamaized.net/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", quality[download_quality][1]));
                        }     
                    }   
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){   
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {                       
                            urls.push(data[i].src.replace("300", quality[download_quality][2]))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + artist + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded(p);
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + artist + "*" + p_a[select_p_a] + ".jpg").toArray();
   
    if (files.length > images.length){
        images = [];
       
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;
   
    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    b_text_array = [];
    b_text_file = artist_folder_path(artist) + "\\" + artist + "_biography_" + lang_query[lang].replace(/\//g,'') + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = text_not_found[lang];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin - scrollbar_w - 10, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_area = Math.floor(Math.max(0, window.Height - t_margin - b_y));
    b_text_visable_rows = Math.floor(b_text_visable_area / b_text_row_height);
    b_text_visable_height = b_text_visable_rows * b_text_row_height;


    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
   
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, lang + 10);         
    _menu.EnableMenuItem(lang + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
    _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0); 
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    IS_ARTIST = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(IS_ARTIST, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _secondgroup = window.CreatePopupMenu();
    _secondgroup.AppendTo(_menu,MF_ENABLED,  "Download quality : " + quality[download_quality][0]);
   
    _secondgroup.AppendMenuItem(MF_ENABLED, 30, "Low");
    _secondgroup.AppendMenuItem(MF_ENABLED, 31, "Medium");
    _secondgroup.AppendMenuItem(MF_ENABLED, 32, "High");
    _secondgroup.CheckMenuRadioItem(30, 32, download_quality + 30);
    _secondgroup.EnableMenuItem(download_quality + 30, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    MF_STRING = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_STRING, 40, "Copy to folder containing track...");
    _menu.AppendMenuItem(MF_STRING, 50, "Open image");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 60, "Save images and text");
    _menu.CheckMenuItem(40, save_images);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        lang = 0;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 11:
        lang = 1;
        window.SetProperty("lang", lang);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + lang_query[lang] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
    case 31:
    case 32:   
        download_quality = ret - 30;
        window.SetProperty("download quality", download_quality);
        break;
    case 40:
        copy_files();
        break;
    case 50:
        try {
            if (images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + artist + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
        } catch(e) {}
        break;
    case 60:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(p){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(p);
        if (images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            get_files_from_dir(artist_folder_path(artist));
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "footer_logo.png")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
       
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);

        var url = "http://static-web.last.fm/static/images/footer_logo.ddcfd65712a6.png"
        var file = "\"" + script_path + "footer_logo.png" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);

    on_text = x >= txt_x && x < sb_x && y  >= txt_y ? true : false;
    on_sb =  x >= sb_x && x < ww && y >= txt_y && y < wh ? true : false;
    on_pic = !on_text && !on_sb ? true : false;

    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        //window.Repaint();
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    window.RepaintRect(sb_x, txt_y, ww, wh);
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
   if (ShiftDown) on_key_down();
   
    if (on_pic && !ShiftDown && !delay){
        get_files_from_dir(artist_folder_path(artist));
        if (files.length > 1){
            delay = true;
            fdelay();
            next_image(delta);
            if (cycle > 0) step = 0;
        }
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.RepaintRect(txt_x, txt_y, ww - txt_x, wh - txt_y);
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }

    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        lang = lang == 1 ? 0 : 1;
        window.SetProperty("lang", lang);
        get_text();
    }

    if (on_pic){
        select_p_a = select_p_a == 1 ? 0 : 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
    }
}

function on_mouse_leave() {
    window.SetCursor(32512);
    on_sb = false;
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(n){
    var dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(n) < 0){
                    fso.deleteFolder(tmp_b_path + name, true);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    if(!img) return;
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

function on_notify_data(name, info) {
    if(name == "panel") {
        if (info == "bio"){
            panel_on = true;
            artist = "";
            on_metadb_changed();
        } else{
            panel_on =  false;
        }
    }
}

//var WshShell = WScript.CreateObject("WScript.Shell")
//WshShell.SendKeys("+{F10}");
kgena_ua
12.11.2016, 21:43
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
09102016

исправил вылет на пустой сборке и изменил function Eval(field).

MC Web, извини, пока личку не смотрю, чищу свой ELP... Действительно медленно как-то работает (из-за возможности изменения размеров коверов в плейлисте), раньше не обращал внимания. Еще делаю seekbar на WHS для ELP (после [EX.UA] Best Of VA :smile: )

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "09102016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww = 200, wh = 200;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 12;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}

var transparent = 200;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var nocover_path = window.GetProperty("nocover path",".\\maybe\\textures\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");

var artist, old_artist;
var path, directory_path;

function clean_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

function artist_folder_path(n) {
    return tmp_b_path + clean_name(n);
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 25);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var b_file;
var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var old_txt_x = 0;
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;
var refresh_txt = true;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
    try {
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
    } catch(e) {}
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 10, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, fader);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, 10, 10, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);         
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval(true) : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist) artist.replace(/^\s+|\s+$/g, "");
    if (artist != old_artist){
        if (!save_images) del_folders();
        get_text();
        get_pic();
        old_artist = artist;
    }
}   

function get_pic() {
    g_img = null;
    files = [];
    images = [];
    selected = 0;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    get_files_from_dir(artist_folder_path(artist));
    if (!g_img && images.length > 0) {
        next_image(0);
    } else {
        get_lastFM_pic(artist_folder_path(artist));
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }
                var found = urls.length;
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    files = utils.Glob(p + "\\" + clean_name(artist) + "*" + p_a[select_p_a] + ".jpg").toArray();
    if (files.length > images.length){
        images = [];
        for (var i = 0; i < files.length; i += 1) {
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    get_files_from_dir(artist_folder_path(artist));///////////////////////////////
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;

    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    //refresh_txt = true;
    s_text = 0;
    text = "";
    b_text_array = [];
    //get_b_text_array();
    b_text_file = artist_folder_path(artist) + "\\" + clean_name(artist) + "_biography_" + clean_name(abc_lang[abc]) + ".txt";
   
    refresh_txt = true;
   
    if (artist && fso.FileExists(b_text_file)){
        text = utils.ReadTextFile(b_text_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_text_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text != "") save_biography_file(text, p);
            if (text == "") text = if_not_found[abc];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;
   
    string_width = Math.max(ww - b_x - t_margin, 0);

    if (Math.abs(txt_x - old_txt_x) > 5 || refresh_txt){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
        old_txt_x = txt_x;
        refresh_txt = false;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    }
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
   _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
    _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    var _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
   
    var MF_ = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images and text");
    _menu.CheckMenuItem(40, save_images);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        abc = 0;
        window.SetProperty("abc", abc);
        get_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
        copy_files();
        break;
    case 40:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0)  {
            next_image(0);
            window.ClearInterval(timer); 
        }
    }, 1500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if (images.length > 1){
                next_image(1);
                step = 0;
            }
        }
        window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
        fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
        window.Repaint();
    }, 42 ); ////10
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && files.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
        window.Repaint();
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        refresh_txt = true;
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
        window.Repaint();
    }
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        get_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    refresh_txt = true;
    get_b_text_array();
}

function del_folders(){
    dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    if (!n) return;
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

kgena_ua
11.10.2016, 23:15
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 3

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version "14052016"


Добавлена возможность сохранения текста.

Безымянный.png


Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "14052016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww = 200, wh = 200;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
    window.Repaint();
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");

var artist, old_artis;
var path, directory_path;

function clean_name(n) {
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

function artist_folder_path(n) {
    return tmp_b_path + clean_name(n);
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var found = 0;
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var b_file;
var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
    try {
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
    } catch(e) {}
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 15, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        if (!save_images) del_folders();
        get_text();
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    g_img = null;
    files = [];
    images = [];
    found = 0;
    selected = 0;
    window.Repaint();
   
    check_folder(artist_folder_path(artist));
    get_files_from_dir(artist_folder_path(artist));
    if (!g_img && images.length > 0) {
        next_image(0);
    } else {
        get_lastFM_pic(artist_folder_path(artist));
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }
                found = Math.min(urls.length, limit); window.Repaint();             
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(resize_image(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function resize_image(img){
    if (!img) return;

    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_text() {
    s_text = 0;
    text = "";
    get_b_text_array();

    b_file = artist_folder_path(artist) + "\\" + clean_name(artist) + "_biography_" + clean_name(abc_lang[abc]) + ".txt";

    if (fso.FileExists(b_file)){
        text = utils.ReadTextFile(b_file);
        get_b_text_array();
    } else{
        get_lastFM_b_text(b_file);
    }
}

function get_lastFM_b_text(p){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            get_b_text_array();
            save_biography_file(text, p);
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;

    string_width = Math.max(ww - b_x - t_margin, 0);

    b_text_array = [];
    if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function save_biography_file(t, p){
    if (!artist) return;
    try {
        file = fso.OpenTextFile( p, 2, true, -1)
        file.WriteLine(t);
        file.Close();
    } catch(e) {
        return;
    }
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
   _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
   _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    var _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 25, align_mode_a[5]);
    _firstgroup.CheckMenuRadioItem(20, 25, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
   
    var MF_ = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images and text");
    _menu.CheckMenuItem(40, save_images);

    //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
    _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        abc = 0;
        window.SetProperty("abc", abc);
        get_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        get_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
        copy_files();
        break;
    case 40:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        //window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;

function get_files_if_loaded(){
    fff = 0;
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (found > 0 && images.length == found && g_img) {
            window.ClearInterval(timer);     
        }
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                step = 0;
            }
        }
    window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
    fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
    window.Repaint();
    }, 10 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        calc_text_height();
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        get_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    get_b_text_array();
}

function del_folders(){
    dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var destination_path;
    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + ".jpg" + nl + "files to";

    var string = input_box(input_box_text, tmp_directory_path, "Foobar 2000");

    if (string){
        destination_path = folder_exists(string);
        if (!destination_path) {
            copy_files();
        } else{
            copy_files_to_folder(destination_path, tmp_files, tmp_p_a);
        }
    }
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    var driver = fso.GetDriveName(n);
    if (!fso.DriveExists(driver)) {
        return "";
    } else {
        var p = "";
        var split_string = [];
        split_string = n.replace(/\\$/g, "").split("\\");

        for (var i = 1; i < split_string.length; i += 1) {
            p = p + clean_path_name(split_string[i]) + "\\";
            try {
                if(!fso.FolderExists(driver + "\\" + p)) fso.CreateFolder(driver + "\\" + p);
            } catch(e) {};
        }
      return driver + "\\" + p;
    }
}

kgena_ua
14.05.2016, 11:16
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 3

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
11042016


Реализована возможность копировать файлы.

Безымянный.png
Безымянный.png (82.26 КБ) Просмотров: 4999

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "11042016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");

var artist, old_artis;
var path, directory_path;

function clean_name(n) {
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

function artist_folder_path(n) {
    return tmp_b_path + clean_name(n);
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var found = 0;
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
    try {
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
    } catch(e) {}
    }

    scrollbar && draw_scrollbar(gr);
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
    directory_path = fb.Titleformat("$directory_path(%path%)").EvalWithMetadb(metadb);
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        if (!save_images) del_folders();
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();
        //get_text();

        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(artist_folder_path(artist));
    get_files_from_dir(artist_folder_path(artist));
    if (!g_img && images.length > 0) {
        next_image(0);
    } else {
        get_lastFM_pic(artist_folder_path(artist));
    }
}
var q, qq;
function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var data2 = div.getElementsByTagName("div");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }
                found = Math.min(urls.length, limit); window.Repaint();             
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    //files = [];
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function get_images(img){
    if (!img) return;

    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            old_string_width = 0;
            get_b_text_array();
            //save_biography_file(text);
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;

    string_width = Math.max(ww - b_x - t_margin, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
   _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
   _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    var _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.CheckMenuRadioItem(20, 24, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
   
    var MF_ = images.length > 0 ? MF_ENABLED : MF_GRAYED;
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images");
    _menu.CheckMenuItem(40, save_images);

//    if (ShiftDown) {   
       //_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       //_menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 30:
        copy_files();
        break;
    case 40:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        //window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;
var fff = 0;
function get_files_if_loaded(){
    fff = 0;
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (found > 0 && images.length == found && g_img) {
            window.ClearInterval(timer);     
        }
       
        fff = fff + 1;
        window.Repaint();
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                step = 0;
            }
        }
    window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
    fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
    window.Repaint();
    }, 10 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        old_string_width = 0;
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    get_b_text_array();
}

function del_folders(){
    dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}

function copy_files(){
    var save_images_state = save_images;
    if (!save_images_state) save_images = true;

    var tmp_files = files;
    var tmp_artist = artist;
    var tmp_p_a = p_a[select_p_a];
    var tmp_directory_path;
   
    if (path.indexOf('://') > 0 || path.indexOf('youtube') == 0 || path.indexOf('cdda') == 0) {
        tmp_directory_path = fb.ProfilePath + tmp_p_a + "\\";
    } else {
        tmp_directory_path = directory_path + "\\" + tmp_p_a + "\\";
    }   
   
    var nl = "\" + chr(10) + \"";
    var input_box_text = "Copy  " + nl + nl + tmp_artist + " " + tmp_p_a + nl + "files to";

    var destination_folder = input_box(input_box_text, tmp_directory_path, "Copy files...");

    if (destination_folder){
        destination_folder = clean_path_name(destination_folder);
        ppp = destination_folder;   
        folder_exists(destination_folder);
        copy_files_to_folder(destination_folder, tmp_files, tmp_p_a);
    }
 
    save_images = save_images_state;
}

function copy_files_to_folder(p, f, pa){
    if (p.length != "\\"){p = p + "\\"}
    for (i in f) {
        if (f[i].indexOf(pa) > 0){
            try {
                fso.CopyFile (f[i], p  , 1 );
            } catch(e) {}
        }
    }
}

function input_box(p_text, d_text, w_title){
    vbe = new ActiveXObject('ScriptControl');
    vbe.Language = 'VBScript';
    return vbe.eval( "InputBox(\"" + p_text + "\",\"" + w_title + "\",\"" + d_text + "\")");
}

function clean_path_name(n) {
    return n.replace(/[\/\*\?\"\<\>\|]/g,'');
}

function folder_exists(n) {
    if (n.length != "\\"){n = n + "\\"}
    for (var i = 3; i < n.length; i += 1) {
        if (n[i] == "\\"){
            if(!fso.FolderExists(n.substr(0, i))) {fso.CreateFolder(n.substr(0, i))};
        }
    }
}
kgena_ua
11.04.2016, 15:12
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version "09042016


Изменения:
- добавлен пункт меню выровнять;
- исправления.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "09042016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");

var artist, old_artis;

function clean_name(n) {
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

function artist_folder_path(n) {
    return tmp_b_path + clean_name(n);
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var align_mode_a = new Array("adjust", "adjust top - center", "adjust top - left", "centre", "centre - top", "stretch");
var align_mode = window.GetProperty("align mode", 0);
var selected = 0;
var files = [];
var images = [];
var found = 0;
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
if (cycle > 0) set_cycle_timer();
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
    try {
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
    } catch(e) {}
    }

    scrollbar && draw_scrollbar(gr);
}

function paint(gr){
    if (g_img){
        var size = calc_img_size(g_img);
        gr.DrawImage(g_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var size = calc_img_size(nc_img);
            gr.DrawImage(nc_img, size.x, size.y, size.width, size.height, size.cx, size.cy, size.cwidth, size.cheight, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        if (!save_images) del_folders();
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();
        //get_text();

        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(artist_folder_path(artist));
    get_files_from_dir(artist_folder_path(artist));
    if (!g_img && images.length > 0) {
        next_image(0);
    } else {
        get_lastFM_pic(artist_folder_path(artist));
    }
}
var q, qq;
function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4) {
            if (xmlhttp1.status == 200) { 
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var data2 = div.getElementsByTagName("div");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }
                found = Math.min(urls.length, limit); window.Repaint();             
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
                doc.close();
                if (found > 0) get_files_if_loaded();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function get_images(img){
    if (!img) return;

    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            old_string_width = 0;
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;

    string_width = Math.max(ww - b_x - t_margin, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, 10, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, 11, "RU text");   
    _menu.CheckMenuRadioItem(10, 11, abc + 10);         
    _menu.EnableMenuItem(abc + 10, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, 12, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, 13, "Follow selected track");   
    _menu.CheckMenuRadioItem(12, 13 , selection_mode + 12);   
   _menu.EnableMenuItem(selection_mode + 12, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, 14, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, 15, "Albums pictures");   
    _menu.CheckMenuRadioItem(14, 15 , select_p_a + 14);   
   _menu.EnableMenuItem(select_p_a + 14, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, 16, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 17, "Fade effect");
    _menu.CheckMenuItem(17, fade_effect);

    var _firstgroup = window.CreatePopupMenu();
    _firstgroup.AppendTo(_menu,MF_ENABLED,  "Align : " + align_mode_a[align_mode]);
   
    _firstgroup.AppendMenuItem(MF_ENABLED, 20, align_mode_a[0]);         
    _firstgroup.AppendMenuItem(MF_ENABLED, 21, align_mode_a[1]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 22, align_mode_a[2]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 23, align_mode_a[3]);
    _firstgroup.AppendMenuItem(MF_ENABLED, 24, align_mode_a[4]);
    _firstgroup.CheckMenuRadioItem(20, 24, align_mode + 20);
    _firstgroup.EnableMenuItem(align_mode + 20, 1);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_GRAYED, 30, "Copy to folder containing track...");
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, 40, "Save images");
    _menu.CheckMenuItem(40, save_images);

//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 100, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 110, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 120, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 10:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 11:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 12:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 13:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 14:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 15:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        g_img = null;
        files = [];
        images = [];
        found = 0;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 16:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 17:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
        align_mode = ret - 20;
        window.SetProperty("align mode", align_mode);
        window.Repaint();
        break;
    case 40:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 100:
        window.Reload();
        break;
    case 110:
        window.ShowProperties();
        break;   
    case 120:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer;
var fff = 0;
function get_files_if_loaded(){
    fff = 0;
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (found > 0 && images.length == found) {
            window.ClearInterval(timer);     
        }
       
        fff = fff + 1;
        window.Repaint();
    }, 500 );
}

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                step = 0;
            }
        }
    window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
    fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
    window.Repaint();
    }, 10 );
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    //if (on_pic && c_selected == selected){ //****
    //    delay = true; //****
    //    fdelay(); //****
    //    if (x > pic_posx) next_image(1); //****
    //    if (x < pic_posx) next_image(-1); //****
    //    if (cycle > 0) step = 0; //****
    //} //****
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        old_string_width = 0;
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
    //} //****
   
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && images[selected]) WshShell.run( '"' + artist_folder_path(artist)+ "\\" + clean_name(artist) + "_"  + selected + "_" + p_a[select_p_a] + ".jpg" + '"' );
    } catch(e) {}
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    get_b_text_array();
}

function del_folders(){
    dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                if (name.indexOf(clean_name(artist)) < 0){
                    fso.deleteFolder(tmp_b_path + name);
                }
            }   
        }
    } catch(e) {};
}

function calc_img_size(img){
    var size = {x:0, y:0, width:0, height:0, cx:0, cy:0, cwidth:0, cheight:0};

    switch(align_mode) {   
   case 0: // adjust      
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
       
        if (sw > sh) x = (ww - img.Width * s) / 2;
        else if (sw < sh) y = (wh - img.height * s) / 2;

        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 1: // adjust top - center
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);

        var x = 0;
        if (sw > sh) x = (ww - img.Width * s) / 2;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;
       
    case 2: // adjust top - left
        var sw = ww / img.Width;
        var sh = wh / img.Height;
        var s = Math.min(sw, sh);
       
        var x = 0;
        var y = 0;
        var width = img.Width * s;
        var height = img.Height * s;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;

   case 3: // centre   
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = Math.round((img.Height - cheight) / 2);
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }   
        var x = 0;         
        var y = 0;         
        var width = ww;         
        var height = wh;         
      break;   
       
   case 4: // centre - top      
      var sr = img.Width / img.Height;   
      var dr = ww / wh;   
      if (sr < dr) {   
         var r = img.Width / ww;
         var cheight = wh * r;
         var cy = 0;
         var cwidth = img.Width;
         var cx = 0;
      } else {   
         var r = img.Height / wh;
         var cwidth = ww * r;
         var cx = Math.round((img.Width - cwidth) / 2);
         var cheight = img.Height;
         var cy = 0;
      }
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
      break;   
       
   case 5: // stretch      
        var x = 0;
        var y = 0;
        var width = ww;
        var height = wh;
        var cx = 0;
        var cy = 0;
        var cwidth = img.Width;
        var cheight = img.Height;
      break;   
    }
   
    size.x = x + p_margin;
    size.y = y + p_margin;
    size.width = width - p_margin * 2;
    size.height = height - p_margin * 2;
    size.cx = cx;
    size.cy = cy;
    size.cwidth = cwidth;
    size.cheight = cheight;
   
    return size;
}
kgena_ua
09.04.2016, 20:36
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version 07042016


Только сделал. Особо не тестировал.

Изменения:
- добавлен пункт меню "Fade effect";
- добавлен пункт меню "Save images". Изображения сохраняются в папке tmp_Biography. При выборе исполнителя, для которого были загружены изображения, скачивание картинок не производится.

Безымянный.png


Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "07042016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};

var script_path = tmp_b_path + "_download\\";
if (!fso.FolderExists(script_path)) {fso.CreateFolder(script_path)};
if (!fso.FileExists(script_path + "download.vbs")) {create_download_file()};

var doc = new ActiveXObject("htmlfile");
var WshShell = new ActiveXObject("WScript.Shell");
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);
var nocover_transparent = window.GetProperty("nocover transparent (0-255)", 100);

load_last_fm_logo();
var logo_img = gdi.Image(script_path + "last_fm_logo.jpg");

var artist, old_artis;

function clean_name(n) {
    return n.replace(/[\/\:\*\?\"\<\>\|]/g,' ');
}

function artist_folder_path(n) {
    return tmp_b_path + clean_name(n);
}

function check_folder(n) {
    if(!fso.FolderExists(n)) {fso.CreateFolder(n)};
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var selected = 0;
var files = [];
var images = [];
var loaded = 0;
var save_images = window.GetProperty("save images", false);
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var fader = 255;
var fade_effect = window.GetProperty("fade effect", false);
var fade_step = window.GetProperty("fade step", 5);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var old_string_width = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_artist = false;
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);
    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows * 2; i += 2) {
    try {
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i / 2 + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text * 2].replace(/^\s+|\s+$/g, ""), b_font, b_color, b_x, b_y + b_text_row_height * i / 2 , ww, wh, DT_LEFT | DT_NOPREFIX );
    } catch(e) {}
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
    gr.GdiDrawText( "", gdi.Font("Arial",12, 0), b_color, 15, 20, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );

}

function paint(gr){
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
        gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, images.length > 0 ? fader : nocover_transparent);
    }
   
    if (logo_img && images.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }

    if (images.length == 0 && nocover){
        try {
            nc_img = gdi.Image(nocover_path);
            var scale_w = (ww - p_margin * 2) / nc_img.Width;
            var scale_h = (wh - p_margin * 2) / nc_img.Height;
            var scale = Math.min(scale_w, scale_h);
            gr.DrawImage(nc_img, p_margin, p_margin, nc_img.Width * scale, nc_img.Height * scale, 0, 0, nc_img.Width, nc_img.Height, 0, nocover_transparent);
        } catch(e) {};
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%").replace(/^\s+|\s+$/g, "");
    if (artist != old_artis){
        s_text = 0;
        text = "";
        old_string_width = 0;
        get_b_text_array()       
        get_lastFM_b_text();

        g_img = null;
        files = [];
        images = [];
        selected = 0;
        if (!save_images) del_folders();
        get_pic();
        old_artis = artist;
    }
}   

function get_pic() {
    if (!artist) return;
   
    check_folder(artist_folder_path(artist));
    get_files_from_dir(artist_folder_path(artist));
    if (!g_img && images.length > 0) {
        next_image(0);
    } else {
        get_lastFM_pic(artist_folder_path(artist));
        load();
    }
}

function get_lastFM_pic(p){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {     
        if (xmlhttp1.readyState == 4) {     
            if (xmlhttp1.status == 200) {     
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }
                loaded = Math.min(urls.length, limit);;               
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + p + "\\" + clean_name(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
              doc.close();
            }
        }     
    }     
}

function get_files_from_dir(p) {
    if (!artist) return;
    p = p + "\\";
    files = [];
    images = [];
    files = utils.Glob(p + "*.*").toArray();
    for (i in files) {
        if (files[i].indexOf(clean_name(artist)) > 0 && files[i].indexOf(p_a[select_p_a]) > 0){
            try {
                images.push(get_images(gdi.Image(files[i])));
            } catch(e) {}
        }
    }
   
   /* try {
        var e = new Enumerator( fso.GetFolder(p).Files );
        for ( ; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf(clean_name(artist)) == 0 && name.indexOf(p_a[select_p_a]) > 0){
                if(fso.FileExists(p + name)){
                    files.push(p + name);
                    images.push(get_images(gdi.Image(p + name)));
                }
            }
        }
    } catch(e) {}
    */
}

function next_image(d){
    fader = fade_effect ? 0 : 255;
    if (d < 0) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1};
    if (d > 0) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1};
    g_img = images[selected];
    if (g_img && fade_effect) fader_timer();
    window.Repaint();
}

function get_images(img){
    if (!img) return;

    var scale_w = (window.Width - p_margin * 2) / img.Width;
    var scale_h = (window.Height - p_margin * 2) / img.Height;
    var scale = Math.min(scale_w, scale_h);
    var nww = img.Width * scale;
    var nwh = img.Height * scale

    var temp_bmp = gdi.CreateImage(nww, nwh);
    var temp_gr = temp_bmp.GetGraphics();
    temp_gr.SetSmoothingMode(2);
    temp_gr.SetInterpolationMode(7);
    temp_gr.DrawImage(img, 0, 0, nww, nwh, 0, 0, img.width, img.height);
    temp_bmp.ReleaseGraphics(temp_gr);
   
    CollectGarbage();
    return temp_bmp;
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;
}

function get_lastFM_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            old_string_width = 0;
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
 
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;

    string_width = Math.max(ww - b_x - t_margin, 0);

    if (old_string_width != string_width){
        b_text_array = [];
        if (text) b_text_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

        old_string_width = string_width;
    }
   
    b_text_rows = b_text_array.length / 2;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = (b_text_rows - b_text_visable_rows);
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
   
    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, i++, "Fade effect");
    _menu.CheckMenuItem(i - 1, fade_effect);
   
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
    _menu.AppendMenuItem(MF_ENABLED, i++, "Save images");
    _menu.CheckMenuItem(i - 1, save_images);
     
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_lastFM_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        images = [];
        loaded = 0;
        g_img = null;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        images = [];
        loaded = 0;
        g_img = null;
        selected = 0;
        window.Repaint();
        get_pic();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 8:
        window.SetProperty("fade effect", !fade_effect);
        fade_effect = window.GetProperty("fade effect");
        break;
    case 9:
        window.SetProperty("Save images", !save_images);
        save_images = window.GetProperty("Save images");
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

//var timer = window.SetInterval(on_timer, 1000);
var timer;

function load(){
    timer && window.ClearInterval(timer);
    timer = window.SetInterval(function() {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
       
        if (images.length == loaded && g_img) {
            window.ClearInterval(timer);     
        }
    }, 500 );
}
/*
function on_timer(id){
    if (images.length < loaded) {
        get_files_from_dir(artist_folder_path(artist));
        if (!g_img && images.length > 0) next_image(0);
    }
   
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (cycle > 0 && step >= cycle){
        if (images.length > 1){
            next_image(1);
            window.Repaint();
            step = 0;
        }
    }
}
*/

var set_cycle = false;

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

var cycle_timer, step = 0;

function set_cycle_timer(){
    cycle_timer && window.ClearInterval(cycle_timer);
    cycle_timer = window.SetInterval(function() {
        step =  set_cycle ? 0 : step + 1;
        if (cycle > 0 && step >= cycle){
            if (images.length > 1){
                next_image(1);
                window.Repaint();
                step = 0;
            }
        }
    window.Repaint();
    }, 1000 );
}

var dis_timer, dis = 0;

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                if (cycle > 0) set_cycle_timer();
                if (cycle == 0) window.ClearInterval(cycle_timer);
                window.ClearInterval(dis_timer)
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

var ftimer;

function fader_timer(){
    fader = 0;
    ftimer && window.ClearInterval(ftimer);
    ftimer = window.SetInterval(function() {
    fader = fader + fade_step;
        if (fader >= 255) {
            fader= 255;
            window.ClearInterval(ftimer);
        }
    window.Repaint();
    }, 10 );
}

function del_folders(){
    dir = fso.GetFolder(tmp_b_path);
    var e = new Enumerator( dir.SubFolders );
    try {
        for(; !e.atEnd(); e.moveNext() ) {
            var name = e.item().Name;
            if (name.indexOf("_download") < 0){
                fso.deleteFolder(tmp_b_path + name);
            }   
        }
    } catch(e) {};
}

function load_last_fm_logo(){
    if(!fso.FileExists(script_path + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + script_path + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + script_path + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(script_path + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
   // if (on_pic && c_selected == selected){ //****
   //     fader = fade_effect && images.length > 1 ? 0 : 255; //****
   //     if (x > pic_posx) {selected = selected >= images.length - 1 ? 0 : selected = selected + 1}; //****
   //     if (x < pic_posx) {selected = selected <= 0 ? images.length - 1 : selected = selected - 1}; //****
   //     g_img = images[selected]; //****
   //      if (g_img && images.length > 1 && fade_effect) fader_timer(); //****
   //     window.Repaint(); //****
   // } //****
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;

        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay && images.length > 1){
        delay = true;
        fdelay();
        next_image(delta);
        if (cycle > 0) step = 0;
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

//var pic_posx = 0; //****
//var c_selected; //****

function on_mouse_lbtn_down(x,y){
    //on_text = x >= txt_x && x < ww  && y >= txt_y && y <= b_y ? true : false; //****
    //on_sb = x >= txt_x && x < ww && y >= b_y ? true : false; //****
    //on_pic = !on_text && !on_sb ? true : false; //****
   
    //if (on_pic){ //****
    //    pic_posx = x; //****
    //    c_selected = selected; //****
   // }
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
   
    //on_pic = false; //****
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_lastFM_b_text();
    }
   
    try {
        if (on_pic && files[selected]) WshShell.run( '"' + files[selected] + '"' );
    } catch(e) {}
}

function on_mouse_leave() {
    window.SetCursor(32512);
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    get_b_text_array();
}


 
kgena_ua
07.04.2016, 15:44
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400

Re: Скрипты для foo_uie_wsh_panel_mod

pois22ple, добрый день, спасибо.
pois22ple:Если запускать foobar с активным пустым плейлистом
Понял.
Когда-то, на другом скрипте, сталкивался с этим. Надо вспомнить.
Исправим.

Добавлено спустя 12 минут 27 секунд:
pois22ple,
function get_files_from_dir(), добавить if (!artist) return;
Код: Выделить всё
function get_files_from_dir() {
    if (!artist) return; 
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(clean_filename(artist)) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}
Позже выложу обновление. Много мелких изменений.

Добавлено спустя 2 часа 20 минут:
Biography Text && Picture. www.last.fm
version "13032016"

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "13032016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

load_last_fm_logo();
var logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");

var artist, old_artis, filename;

function clean_filename(filename) {
    return filename.replace(/[\/\:\*\?\"\<\>\|\s]/g,'_');
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", true);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var a_text_row_height = 0;
var b_text_row_height = 0;
var b_text_rows = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);

    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX );   

    for (var i = 0; i < b_text_visable_rows; i++) {
        gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT | DT_NOPREFIX );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT | DT_NOPREFIX );
    }

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText("", gdi.Font("Arial",12, 0), b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]);
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path);
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        if (files.length > 0){
            g_img = g_img.CreateRawBitmap();
            gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
        } else {
            gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100);
        }
    }
   
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    if (b_text_rows > b_text_visable_rows){ scrollbar_h = Math.max(5, scrollbar_h)}
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;
   
    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;   
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);   
    return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    //return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis){
        CollectGarbage();
        g_img = null;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_b_text();
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();       
        old_artis = artist;
    }
}     

function get_pic(){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);     
    xmlhttp1.open("GET", url1, true);     
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp1.send(null);     
    xmlhttp1.onreadystatechange = function () {     
        if (xmlhttp1.readyState == 4) {     
            if (xmlhttp1.status == 200) {     
                doc.open();     
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp1.responsetext;
                var data = div.getElementsByTagName("img");
                var urls = [];
                for (i = 0; i < data.length; i++) {     
                    if (data[i].className == "image-list-image" && select_p_a == 0){       
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) {
                            urls.push(data[i].src.replace("avatar170s", "770x0"));
                        }     
                    }       
                    if (data[i].className == "album-grid-album-art" && select_p_a == 1){         
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) {
                            urls.push(data[i].src.replace("300", ""))
                        }     
                    }       
                }     
                for (i = 0; i < Math.min(urls.length, limit); i++) {     
                    file = "\"" + tmp_b_path + clean_filename(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";     
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);
                }     
              doc.close();
            }       
        }     
    }     
}

function get_files_from_dir() {
    if (!artist) return; 
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(clean_filename(artist)) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

function get_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send(null);
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
   
    var strings_array = [];
    b_text_array = [];
   
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    a_text_row_height = temp_gr.CalcTextHeight("text", a_font);
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font);
   
    b_x = txt_x + t_margin;
    b_y = a_y + a_text_row_height + b_text_row_height;

    var string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;

    b_text_visable_height = Math.round(Math.max(0, wh - t_margin - b_y));
    b_text_visable_rows = Math.round(b_text_visable_height / b_text_row_height);

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = b_text_rows - b_text_visable_rows;
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
     
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1);

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
     
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {
        get_files_from_dir();
        window.Repaint();
    };
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                window.ClearInterval(dis_timer);               
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

function load_last_fm_logo(){
    if(!fso.FileExists(tmp_b_path + "\\download\\" + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "download.vbs" )
       
        var text =   
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
 
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - (a_text_row_height + t_margin * 2) ? wh - (a_text_row_height + t_margin * 2) : txt_y;
        get_b_text_array();
    }

    if (on_sb_down && scrollbar && b_text_rows > b_text_visable_rows){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        delay = true;
        fdelay();
        get_files_from_dir();
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};
    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (on_pic && files[selected]) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - (a_text_row_height + t_margin * 2) && txt_y >= 0 ? wh - (a_text_row_height + t_margin * 2) : txt_y;
   
    get_b_text_array();
}
kgena_ua
13.03.2016, 13:04
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 4

Re: Скрипты для foo_uie_wsh_panel_mod

Biography Text && Picture. www.last.fm
version 27022016


Дополнения:
- максимально вывел в меню Properties необходимые для пользователя настройки;
- изменение размера шрифта (10 - 16) - Shift + колесо мыши на тексте;
- размер шрифта для артиста привязан к размеру шрифта биографии через переменную font size: artist (delta) в меню Properties;
- добавил прозрачность для изображения nocover.
Безымянный.png

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "27022016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   

ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};
/*
function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();
*/

var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

var last_fm_logo;
load_last_fm_logo();

var artist, old_artis;

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var pic_scroll = false;

var scrollbar = window.GetProperty("scrollbar", false);
var sb_down = false;
var sb_scroll = false;
var scrollbar_k;
var posy = 0;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var artist_x, artist_y;
var b_x = 0, b_y = 0;
var text = "";
var s_text = 0;
var string_width;
var strings_array = [];
var b_text_rows = 0;
var b_text_row_height = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var k_down = false;
var text_scroll = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var select_p_a_old;
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);

    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), artist_x + 1, artist_y + 2, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    gr.GdiDrawText(artist, a_font, a_color, artist_x, artist_y, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   

    for (var i = 0; i < b_text_visable_rows; i++) { 
        gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT );
    } 

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText("", b_font, b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]); 
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path); 
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        if (files.length > 0){
            g_img = g_img.CreateRawBitmap();
            gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
        } else {
            gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100); 
        }
    }
   
    logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}


function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change(); 
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;    
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);   
    //return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis || select_p_a != select_p_a_old){
        CollectGarbage();
        g_img = null;
        files = [];
        del_files_from_dir();
        selected = 0;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_pic();
        old_artis = artist;
        select_p_a_old = select_p_a;
    }
}      

function get_pic(){      
    var url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);      
    xmlhttp.open("GET", url1, true);      
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");      
    xmlhttp.send();      
    xmlhttp.onreadystatechange = function () {      
        if (xmlhttp.readyState == 4) {      
            if (xmlhttp.status == 200) {      
                doc.open();      
              var div = doc.createElement("div");
              div.innerHTML = xmlhttp.responsetext;
              var data = div.getElementsByTagName("img");
              var urls = [];
                for (i = 0; i < data.length; i++) {      
                    if (data[i].className == "image-list-image"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) urls.push(data[i].src.replace("avatar170s", ""));       
                    }       
                    if (data[i].className == "album-grid-album-art"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) urls.push(data[i].src.replace("300", ""));       
                    }        
                }      
                for (i = 0; i < Math.min(urls.length, limit); i++) {      
                    file = "\"" + tmp_b_path + artist + "_"  + i + "_" +p_a[select_p_a] + ".jpg" + "\"";      
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);       
                }      
              doc.close();
            }       
            get_b_text();      
        }      
    }      
}

function get_files_from_dir() {
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(artist) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

/*function get_files_from_dir() {
    files = [];
    files = utils.Glob(tmp_b_path + artist + "*.*").toArray();
}
*/
function get_b_text(){
    var url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp.open("GET", url2, true);
    xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp.send();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    artist_x = txt_x + t_margin;
    artist_y = txt_y + t_margin;
    strings_array = [];
    b_text_array = [];
   
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    b_x = txt_x + t_margin;
    b_y = txt_y + temp_gr.CalcTextHeight("text", a_font) + t_margin * 2;

    b_text_row_height = temp_gr.CalcTextHeight("text", b_font)
    string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;
    b_text_visable_rows = Math.round((wh - b_y - 10) / b_text_row_height);
    b_text_visable_height = Math.round(wh - b_y - 10);

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = b_text_rows - b_text_visable_rows;
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
      
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1); 

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
      
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection_mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        on_metadb_changed();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {get_files_from_dir(); window.Repaint();};
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                window.ClearInterval(dis_timer);               
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

/*
function del_files_from_dir() {
    del_files = [];
    del_files = utils.Glob(tmp_b_path + "*.*").toArray();
   
    for (i in del_files) {
        try {
            fso.deleteFile(del_files[i]);
        } catch(e) {};
    }
}
*/

function load_last_fm_logo(){
    if(!fso.FileExists(tmp_b_path + "\\download\\" + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "download.vbs" )
       
        var text =    
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    text_scroll = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    sb_scroll =  x > ww - 20 && y  >= txt_y ? true : false;
    pic_scroll = !text_scroll && !sb_scroll ? true : false;
   
    if (k_down){
        txt_x = x - delta_x ;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - 50 ? wh - 50: txt_y;
        get_b_text_array();
    }

    if (sb_down && scrollbar){
        posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (!delay && pic_scroll && !ShiftDown){
        delay = true;
        fdelay();
        get_files_from_dir(); 
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};

    }
   
    if (text_scroll && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (!delay && text_scroll && ShiftDown){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        get_b_text_array();
    }
   
    if (set_cycle && pic_scroll) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

function on_mouse_lbtn_down(x,y){
    if (text_scroll){
        k_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (sb_scroll){
        sb_down = true;
        posy = s_text * scrollbar_k;
        delta_y = posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    k_down = false;
    sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (text_scroll){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (files[selected] && pic_scroll) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - 50 && txt_y >= 0 ? wh - 50 : txt_y;
   
    get_b_text_array();
}
kgena_ua
27.02.2016, 16:23
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 1

Re: Скрипты для foo_uie_wsh_panel_mod

:smile: Блин, до меня только дошло. Имя файла, вернее недопустимые символы в имени файла.
Файл просто не сохранялся на диске. :oops:
Сайт все воспринимает нормально, и я же видел это:
seriousstas:http://www.last.fm/ru/music/AC%2FDC

Добавлено спустя 4 часа 49 минут:
zeremy,
такой вариант функции:
Код: Выделить всё
function clean_filename(filename) {
    return filename.replace(/[\/\:\*\?\"\<\>\|\s]/g,'_');
}

Добавлено спустя 4 часа 5 минут:
duzzy, привет. Я тут немного переделал скрипт, а именно:
если раньше загрузка текста - get_b_text() вызывалась из get_pic(), то теперерь из on_metadb_changed(), что мне кажется более правильным. Теперь при выборе артист/обложка не перегружается текст биографии.
Нужно протестировать на момент проблем с быстрым переключением.

Скрипт без изменений, связанных с выбором языков, от zeremy.
Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua"
// @version "09032016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==

function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
function RGBA(r,g,b,a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); }
function getRed(color) {return ((color >> 16) & 0xff);};
function getGreen(color) {return ((color >> 8) & 0xff);};
function getBlue(color) {return (color & 0xff);};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;

var ww,wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font(){
    a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
    b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}   
/*
ColorTypeCUI = {
    text: 0,
    selection_text: 1,
    inactive_selection_text: 2,
    background: 3,
    selection_background: 4,
    inactive_selection_background: 5,
    active_item_frame: 6
};

function get_color(){   
    bgcolor = window.GetColorCUI(ColorTypeCUI.background);
    a_color = window.GetColorCUI(ColorTypeCUI.text);
    b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();

function on_colors_changed(){
    get_color();
}
*/
var bgcolor = RGB(31,41,48);
var a_color = RGB(220,220,220);
var b_color = RGB(255,255,230);

var transparent = 200;

//var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if(!fso.FolderExists(tmp_b_path)) {fso.CreateFolder(tmp_b_path)};
if(!fso.FolderExists(tmp_b_path + "\\download\\")) {fso.CreateFolder(tmp_b_path + "\\download\\")};
if(!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {create_download_file()};
var nocover_path = window.GetProperty("nocover path",".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

load_last_fm_logo();
var logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");

var artist, old_artis, filename;

function clean_filename(filename) {
    return filename.replace(/[\/\:\*\?\"\<\>\|\s]/g,'_');
}

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit",5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var on_pic = false;

var scrollbar = window.GetProperty("scrollbar", false);
var scrollbar_k;
var sb_posy = 0;
var on_sb = false;
var on_sb_down = false;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var a_x, a_y;
var b_x, b_y;
var text = "";
var s_text = 0;
var b_text_rows = 0;
var b_text_row_height = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var on_text = false;
var on_text_down = false;

var abc_lang = new Array("", "ru/");
var abc = window.GetProperty("abc", 0);
var if_not_found = new Array(". . .", ". . .");
var select_p_a = window.GetProperty("pictures/albums", 0);
var select_p_a_old;
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;
on_item_focus_change();

function on_paint(gr){   
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);

    paint(gr);   

    if(set_cycle){   
        gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
        var txt_cycle = cycle == 0 ? "off" : cycle + " sec";   
        set_cycle && gr.GdiDrawText("auto cycle \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    } else{   
        gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor),getGreen(bgcolor),getBlue(bgcolor),transparent));   
    }   

    gr.GdiDrawText(artist, a_font, RGB(0,0,0), a_x + 1, a_y + 2, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   
    gr.GdiDrawText(artist, a_font, a_color, a_x, a_y, ww - a_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS );   

    for (var i = 0; i < b_text_visable_rows; i++) { 
        gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0,0,0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT );
        gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT );
    } 

    scrollbar && draw_scrollbar(gr);

    gr.GdiDrawText("", b_font, b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}

function paint(gr){
    g_img = gdi.Image(files[selected]); 
    if (!g_img && nocover){
        try {
            g_img = gdi.Image(nocover_path); 
        } catch(e) {};
    }
   
    if (g_img){
        var scale_w = (ww - p_margin * 2) / g_img.Width;
        var scale_h = (wh - p_margin * 2) / g_img.Height;
        var scale = Math.min(scale_w, scale_h);
       
        if (files.length > 0){
            g_img = g_img.CreateRawBitmap();
            gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
        } else {
            gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100); 
        }
    }
   
    if (logo_img && files.length == 0 && !nocover){
        gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);   
    }
}

function draw_scrollbar(gr){
    scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
    scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

    gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
    on_item_focus_change();
}

function on_playback_new_track() {
    on_item_focus_change();
}

function on_playback_dynamic_info_track() {
    on_item_focus_change();
}

function on_playback_stop() {
    on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change(); 
}

function on_item_focus_change() {
    switch (selection_mode) {
    case 0:
        metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();   
        break;   
    case 1:   
       metadb = fb.GetFocusItem();
        break;    
    }   
    if (metadb) on_metadb_changed();   
}   

function Eval(field) {   
    if (!metadb) return;   
    path = fb.Titleformat("%path%").EvalWithMetadb(metadb);   
    //return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);   
    return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);   
}   

function on_metadb_changed() {
    if (!metadb) return;   
    artist = Eval("%artist%");
    if (artist != old_artis || select_p_a != select_p_a_old){
        CollectGarbage();
        g_img = null;
        s_text = 0;
        text = "";
        get_b_text_array()       
        get_b_text();
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();       
        old_artis = artist;
        select_p_a_old = select_p_a;
    }
}      

function get_pic(){
    xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");     
    var url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);      
    xmlhttp1.open("GET", url1, true);      
    xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");      
    xmlhttp1.send();      
    xmlhttp1.onreadystatechange = function () {      
        if (xmlhttp1.readyState == 4) {      
            if (xmlhttp1.status == 200) {      
                doc.open();      
              var div = doc.createElement("div");
              div.innerHTML = xmlhttp1.responsetext;
              var data = div.getElementsByTagName("img");
              var urls = [];
                for (i = 0; i < data.length; i++) {      
                    if (data[i].className == "image-list-image"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0) urls.push(data[i].src.replace("avatar170s", ""));       
                    }       
                    if (data[i].className == "album-grid-album-art"){        
                        if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0) urls.push(data[i].src.replace("300", ""));       
                    }        
                }      
                for (i = 0; i < Math.min(urls.length, limit); i++) {      
                    file = "\"" + tmp_b_path + clean_filename(artist) + "_"  + i + "_" + p_a[select_p_a] + ".jpg" + "\"";      
                    WshShell.Run(vbs + " " + urls[i] + " " + file, false);       
                }      
              doc.close();
            }       
            //get_b_text();      
        }      
    }      
}

function get_files_from_dir() {
    files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        if (name.indexOf(clean_filename(artist)) == 0){
            files.push(tmp_b_path + name);
        }
        e.moveNext();
    }
}

/*function get_files_from_dir() {
    files = [];
    files = utils.Glob(tmp_b_path + artist + "*.*").toArray();
}
*/
function get_b_text(){
    xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
    var url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
    xmlhttp2.open("GET", url2, true);
    xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttp2.send();
    xmlhttp2.onreadystatechange = function () {
        if (xmlhttp2.readyState == 4) {
            if (xmlhttp2.status == 200) {
                doc.open();
                var div = doc.createElement("div");
                div.innerHTML = xmlhttp2.responsetext;
                var data = div.getElementsByTagName("div");
                for (i = 0; i < data.length; i++) {
                    if (data[i].className == "wiki-content") {
                        text = strip_tags(data[i].innerHTML);
                        break;
                    }
                }
                doc.close();
            }
            if (text == "") text = if_not_found[abc];
            get_b_text_array();
        }
    }
}

function strip_tags(t) {
    doc.open();
    var div = doc.createElement("div");
    div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
    var text = div.innerText;
    doc.close();
    return text;
}

function get_b_text_array() {
    a_x = txt_x + t_margin;
    a_y = txt_y + t_margin;
   
    var strings_array = [];
    b_text_array = [];
   
    temp_bmp = gdi.CreateImage(1, 1);
    temp_gr = temp_bmp.GetGraphics();

    b_x = txt_x + t_margin;
    b_y = txt_y + temp_gr.CalcTextHeight("text", a_font) + t_margin * 2;

    var string_width = Math.max(ww - b_x - 10, 0);

    if (text) strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

    for (var i = 0; i < strings_array.length; i += 2) {
        b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
    }

    b_text_rows = b_text_array.length;
    b_text_row_height = temp_gr.CalcTextHeight("text", b_font)
    b_text_visable_rows = Math.round((wh - b_y - 10) / b_text_row_height);
    b_text_visable_height = Math.round(wh - b_y - 10);

    temp_bmp.ReleaseGraphics(temp_gr);
    temp_bmp.Dispose();
    temp_gr = null;
    temp_bmp = null;

    if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
        s_text = b_text_rows - b_text_visable_rows;
    };
   
    scrollbar_k = b_text_visable_height / b_text_rows;
    window.Repaint();
}

function on_mouse_rbtn_up (x, y){     
    var _menu = window.CreatePopupMenu();
    var i = 1;

    MF_ENABLED = 0x00000000;   
    MF_GRAYED = 0x00000001;   
    MF_SEPARATOR = 0x00000800;   
      
    _menu.AppendMenuItem(MF_ENABLED, i++, "EN text");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "RU text");   
    _menu.CheckMenuRadioItem(1, i, abc + 1);         
    _menu.EnableMenuItem(abc + 1, 1);     

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
       
    _menu.AppendMenuItem(MF_ENABLED, i++, "Prefer now playing");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Follow selected track");   
    _menu.CheckMenuRadioItem(i - 2, i , selection_mode + 3);   
   _menu.EnableMenuItem(selection_mode + 3, 1);
       
    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Artist pictures");   
    _menu.AppendMenuItem(MF_ENABLED, i++, "Albums pictures");   
    _menu.CheckMenuRadioItem(i - 2, i , select_p_a + 5);   
   _menu.EnableMenuItem(select_p_a + 5, 1); 

    _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
    var is_artist = artist ? MF_ENABLED : MF_GRAYED;   
    _menu.AppendMenuItem(is_artist, i++, "last.fm Artist");   
      
//    if (ShiftDown) {   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 10, "Reload");   
        _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);   
        _menu.AppendMenuItem(MF_ENABLED, 20, "Properties");   
        _menu.AppendMenuItem(MF_ENABLED, 30, "Configure ...");
//    }

    ret = _menu.TrackPopupMenu(x,y);

    switch (ret) {
    case 1:
        abc = 0;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 2:
        abc = 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        text = "";
        get_b_text();
        break;
    case 3:
        selection_mode = 0;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 4:
        selection_mode = 1;
        window.SetProperty("selection mode", selection_mode);
        on_item_focus_change();
        break;
    case 5:
        select_p_a = 0;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        //on_metadb_changed();
        break;
    case 6:
        select_p_a = 1;
        window.SetProperty("pictures/albums", select_p_a);
        del_files_from_dir();
        files = [];
        selected = 0;
        get_pic();
        //on_metadb_changed();
        break;
    case 7:
        WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
        break;
    case 10:
        window.Reload();
        break;
    case 20:
        window.ShowProperties();
        break;   
    case 30:
        window.ShowConfigure();   
        break;   
   }
    _menu.Dispose();   
    return true;   
}   

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
    step =  set_cycle || cycle == 0 ? 0 : step + 1;
    if (files.length == 0) {
        get_files_from_dir();
        window.Repaint();
    };
   
    if (cycle > 0 && step >= cycle){
        selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
        window.Repaint();
        step = 0;
    }
}

function on_key_down(vkey) {
    if (vkey == 16){
        set_cycle = true;
        dis_set();
        window.Repaint();
    }
}

function dis_set(){
    dis = 0;
    dis_timer && window.ClearInterval(dis_timer);
    dis_timer = window.SetInterval(function() {
        if (set_cycle) {
            dis++;
            if(dis == 1) {
                set_cycle = false;
                window.ClearInterval(dis_timer);               
                window.Repaint();
            };
        }
    }, 1000 );
}

var delay = false;

function fdelay(){
    var delay_timer = window.SetTimeout(function() {
        delay = false;
        window.ClearTimeout(delay_timer);
    }, 200);
}

function del_files_from_dir() {
    var del_files = [];
    var e = new Enumerator( fso.GetFolder(tmp_b_path).Files );
    while ( !e.atEnd() ) {
        var name = e.item().Name;
        try {
            fso.deleteFile(tmp_b_path + name );
        } catch(e) {};
        e.moveNext();
    }
}

/*
function del_files_from_dir() {
    del_files = [];
    del_files = utils.Glob(tmp_b_path + "*.*").toArray();
   
    for (i in del_files) {
        try {
            fso.deleteFile(del_files[i]);
        } catch(e) {};
    }
}
*/

function load_last_fm_logo(){
    if(!fso.FileExists(tmp_b_path + "\\download\\" + "last_fm_logo.jpg")) {
        var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_logo.jpg" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
        var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
        var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_ico.ico" + "\"";
        WshShell.Run(vbs + " " + url + " " + file, false);
    }
}

function create_download_file() {
    try {
        file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "download.vbs" )
       
        var text =    
            "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +   
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "url = WScript.Arguments(0)" + "\n\r" +   
            "file = WScript.Arguments(1)" + "\n\r"  + "\n\r" +   

            "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +   
            "If objFSO.Fileexists(file) Then" + "\n\r" +   
            "   Set objFSO = Nothing" + "\n\r" +
            "   WScript.Quit" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +   
            "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +   
            "objXMLHTTP.send()" + "\n\r" + "\n\r" +   

            "If objXMLHTTP.Status = 200 Then" + "\n\r" +   
            "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
            "   objADOStream.Open" + "\n\r" +
            "   objADOStream.Type = 1" + "\n\r" +
            "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
            "   objADOStream.Position = 0" + "\n\r" +
            "   objADOStream.SaveToFile file" + "\n\r" +
            "   objADOStream.Close" + "\n\r" +
            "   Set objADOStream = Nothing" + "\n\r" +
            "End If" + "\n\r" + "\n\r" +   

            "Set objFSO = Nothing" + "\n\r" +   
            "Set objXMLHTTP = Nothing"   
        ;

        file.WriteLine(text);
        file.Close();
    } catch(e) {};
}

function on_mouse_move(x, y) {
    window.SetCursor(32649);
   
    on_text = x >= txt_x && x < ww - 20 && y  >= txt_y ? true : false;
    on_sb =  x > ww - 20 && y  >= txt_y ? true : false;
    on_pic = !on_text && !on_sb ? true : false;
   
    if (on_text_down){
        txt_x = x - delta_x;
        txt_y = y - delta_y;

        txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50: txt_x;
        txt_y = txt_y <= 0 ? 0 : txt_y >= wh - 50 ? wh - 50: txt_y;
        get_b_text_array();
    }

    if (on_sb_down && scrollbar){
        sb_posy = y + delta_y;
        s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(sb_posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
        window.Repaint();
    }
}

function on_mouse_wheel(delta) {
    ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
   
    if (on_pic && !ShiftDown && !delay){
        delay = true;
        fdelay();
        get_files_from_dir(); 
        if (delta < 0) {selected = selected <= 0 ? files.length - 1 : selected = selected - 1};
        if (delta > 0) {selected = selected >= files.length - 1 ? 0 : selected = selected + 1};

    }
   
    if (on_text && !ShiftDown){
        if (b_text_rows > b_text_visable_rows){
            if (delta < 0) {s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1}
            if (delta > 0) {s_text = s_text <= 0 ? 0 : s_text -= 1}
        }
    }
   
    if (on_text && ShiftDown && !delay){
        delay = true;
        fdelay();
        if (delta < 0) {font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;};
        if (delta > 0) {font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;};
        window.SetProperty("font size: biography", font_size_b);
        get_font();
        get_b_text_array();
    }
   
    if (set_cycle && on_pic) {
        if (delta < 0) {cycle = cycle <= 0 ? 0 : cycle - 5;};
        if (delta > 0) {cycle = cycle >= 60 ? 60 : cycle + 5;};
        window.SetProperty("auto cycle (sec)", cycle);
    }
    window.Repaint();
}

function on_mouse_lbtn_down(x,y){
    if (on_text){
        on_text_down = true;
        delta_x = x - txt_x;
        delta_y = y - txt_y;
    }
    if (on_sb){
        on_sb_down = true;
        sb_posy = s_text * scrollbar_k;
        delta_y = sb_posy - y;
    }
}

function on_mouse_lbtn_up(x,y){
    window.SetProperty("txt_x", txt_x);
    window.SetProperty("txt_y", txt_y);
    on_text_down = false;
    on_sb_down = false;
}

function on_mouse_lbtn_dblclk (x,y){
    if (on_text){
        abc = abc == 1 ? 0 : 1;
        window.SetProperty("abc", abc);
        s_text = 0;
        b_text_array = [];
        text = "";
        get_b_text();
    }
    if (on_pic && files[selected]) WshShell.run( '"' + files[selected] + '"' );
}

function on_mouse_leave() {
    window.SetCursor(32512);
    window.Repaint();
}

function on_size(){
    ww = window.Width;   
    wh = window.Height;
   
    txt_x = window.GetProperty("txt_x");
    txt_y = window.GetProperty("txt_y");

    txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
    txt_y = txt_y >= wh - 50 && txt_y >= 0 ? wh - 50 : txt_y;
   
    get_b_text_array();
}
kgena_ua
09.03.2016, 07:17
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
  • 2

Re: Скрипты для foo_uie_wsh_panel_mod

kgena_ua
duzzy
seriousstas

Problem is with illegal characters in the filename.

Код: Выделить всё
// ==PREPROCESSOR==
// @name "Biography Text && Picture. www.last.fm"
// @author "kgena_ua - mod zeremy for multilanguage "
// @version "07032016"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==


function RGB(r, g, b) {
   return (0xff000000 | (r << 16) | (g << 8) | (b));
}
function RGBA(r, g, b, a) {
   return ((a << 24) | (r << 16) | (g << 8) | (b));
}
function getRed(color) {
   return ((color >> 16) & 0xff);
};
function getGreen(color) {
   return ((color >> 8) & 0xff);
};
function getBlue(color) {
   return (color & 0xff);
};

DT_LEFT = 0x00000000;
DT_RIGHT = 0x00000002;
DT_CENTER = 0x00000001;
DT_VCENTER = 0x00000004;
DT_SINGLELINE = 0x00000020;
DT_WORD_ELLIPSIS = 0x00040000;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;
DT_END_ELLIPSIS = 0x00008000;

var ww, wh;

var font_name_a = window.GetProperty("font name: artist", "Arial");
var font_name_b = window.GetProperty("font name: biography", "Arial");
var font_size_a_d = window.GetProperty("font size: artist (delta)", 0);
var font_size_b = window.GetProperty("font size: biography", 12);
var a_font_style = window.GetProperty("font style: artist", 1);
var b_font_style = window.GetProperty("font style: biography", 0);
var min_font_size = 10;
var max_font_size = 16;

var a_font, b_font;
get_font();

function get_font() {
   a_font = gdi.Font(font_name_a, font_size_b + font_size_a_d, a_font_style);
   b_font = gdi.Font(font_name_b, font_size_b, b_font_style);
}

ColorTypeCUI = {
   text : 0,
   selection_text : 1,
   inactive_selection_text : 2,
   background : 3,
   selection_background : 4,
   inactive_selection_background : 5,
   active_item_frame : 6
};
/*
function get_color(){
bgcolor = window.GetColorCUI(ColorTypeCUI.background);
a_color = window.GetColorCUI(ColorTypeCUI.text);
b_color = window.GetColorCUI(ColorTypeCUI.inactive_selection_text);
}

get_color();
 */

var bgcolor = RGB(31, 41, 48);
var a_color = RGB(220, 220, 220);
var b_color = RGB(255, 255, 230);

var transparent = 200;

var doc = new ActiveXObject("htmlfile");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var WshShell = new ActiveXObject("WScript.Shell");
var script_path = fb.ProfilePath + "\\tmp_Biography\\download\\";
var vbs = "cscript //nologo \"" + script_path + "download.vbs\"";

var tmp_b_path = fb.ProfilePath + "\\tmp_Biography\\";
if (!fso.FolderExists(tmp_b_path)) {
   fso.CreateFolder(tmp_b_path)
};
if (!fso.FolderExists(tmp_b_path + "\\download\\")) {
   fso.CreateFolder(tmp_b_path + "\\download\\")
};
if (!fso.FileExists(tmp_b_path + "\\download\\" + "download.vbs")) {
   create_download_file()
};
var nocover_path = window.GetProperty("nocover path", ".\\nocover\\nocover.png");
var nocover = window.GetProperty("nocover image", false);

var last_fm_logo;
load_last_fm_logo();

var artist, old_artis, filename;

var g_img = null;
var p_margin = window.GetProperty("margin: picture", 10);
var files = [], selected = 0;
var limit = window.GetProperty("download limit", 5);
var cycle = window.GetProperty("auto cycle (sec)", 0);
var pic_scroll = false;

var scrollbar = window.GetProperty("scrollbar", false);
var sb_down = false;
var sb_scroll = false;
var scrollbar_k;
var posy = 0;

var t_margin = window.GetProperty("margin: text", 10);
var txt_x = window.GetProperty("txt_x", window.Width / 2);
var txt_y = window.GetProperty("txt_y", window.Height / 2);
var delta_x, delta_y;
var artist_x, artist_y;
var b_x = 0, b_y = 0;
var text = "";
var s_text = 0;
var string_width;
var strings_array = [];
var b_text_rows = 0;
var b_text_row_height = 0;
var b_text_visable_rows = 0;
var b_text_visable_height = 0;
var b_text_array = [];
var k_down = false;
var text_scroll = false;

var abc_lang = new Array("", "ru/", "es/", "fr/", "it/", "ja/", "pl/", "pt/", "de/", "sv/", "tr/", "zh/");
var abc = window.GetProperty("abc", 0);

var if_not_found = new Array("Nothing found", "Ничего не найдено", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found", "Nothing found"); // var if_not_found = new Array(_("Nothing found"), _("Nothing found"));
var select_p_a = window.GetProperty("pictures/albums", 0);
var select_p_a_old;
var p_a = new Array("images", "albums");

var selection_mode = window.GetProperty("selection mode", 0);
var metadb;

function _(s) {
   switch (abc) {
   case 1:
      if (typeof(ru) != 'undefined' && ru[s]) {
         return ru[s];
      }
      return s;
      break;
   case 2:
      if (typeof(es) != 'undefined' && es[s]) {
         return es[s];
      }
      return s;
      break;
   case 3:
      if (typeof(fr) != 'undefined' && fr[s]) {
         return fr[s];
      }
      return s;
      break;
   case 4:
      if (typeof(it) != 'undefined' && it[s]) {
         return it[s];
      }
      return s;
      break;
   case 5:
      if (typeof(ja) != 'undefined' && ja[s]) {
         return ja[s];
      }
      return s;
      break;
   case 6:
      if (typeof(pl) != 'undefined' && pl[s]) {
         return pl[s];
      }
      return s;
      break;
   case 7:
      if (typeof(pt) != 'undefined' && pt[s]) {
         return pt[s];
      }
      return s;
      break;
   case 8:
      if (typeof(de) != 'undefined' && de[s]) {
         return de[s];
      }
      return s;
      break;
   case 9:
      if (typeof(sv) != 'undefined' && sv[s]) {
         return sv[s];
      }
      return s;
      break;
   case 10:
      if (typeof(tr) != 'undefined' && tr[s]) {
         return tr[s];
      }
      return s;
      break;
   case 11:
      if (typeof(zh) != 'undefined' && zh[s]) {
         return zh[s];
      }
      return s;
      break;

   default:
      return s;
   }
}

var ru = {
   "Nothing found" : "Ничего не найдено",
   "off" : "Отключено",
   "sec" : "сек",
   "auto cycle" : "Зацикливание изображений",
   "Prefer now playing" : "Предпочитать воспроизводимый",
   "Follow selected track" : "Следовать за выбранным треком",
   "Artist pictures" : "Фото исполнителя",
   "Albums pictures" : "Обложка альбома",
   "last.fm Artist" : "Страничка исполнителя на Last.fm",
   "Reload" : "Перезагрузить",
   "Properties" : "Свойства WSH",
   "Configure..." : "Настройки WSH..."
};

var es = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var fr = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var it = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var ja = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var pl = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var pt = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var de = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var sv = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var tr = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

var zh = {
   "Nothing found" : "",
   "off" : "",
   "sec" : "",
   "auto cycle" : "",
   "Prefer now playing" : "",
   "Follow selected track" : "",
   "Artist pictures" : "",
   "Albums pictures" : "",
   "last.fm Artist" : "",
   "Reload" : "",
   "Properties" : "",
   "Configure..." : ""
};

on_item_focus_change();

//Remove false string from file names
function clean_filename(filename) {
   return filename.replace(/[\/\\|:]/g, '-').replace(/\*/g, 'x').replace(/"/g, "''").replace(/[?<>]/g, '_');
}

function on_paint(gr) {
   !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, bgcolor);

   paint(gr);

   if (set_cycle) {
      gr.FillSolidRect(0, 0, ww, wh, RGBA(getRed(bgcolor), getGreen(bgcolor), getBlue(bgcolor), transparent));
      var txt_cycle = cycle == 0 ? _("off") : cycle + " " + _("sec");
      set_cycle && gr.GdiDrawText(_("auto cycle") + " \n" + txt_cycle, b_font, b_color, 15, 15, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS);
   } else {
      gr.FillSolidRect(txt_x, txt_y, ww - txt_x, wh - txt_y, RGBA(getRed(bgcolor), getGreen(bgcolor), getBlue(bgcolor), transparent));
   }

   gr.GdiDrawText(artist, a_font, RGB(0, 0, 0), artist_x + 1, artist_y + 2, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX);
   gr.GdiDrawText(artist, a_font, a_color, artist_x, artist_y, ww - artist_x - t_margin, wh, DT_LEFT | DT_WORD_ELLIPSIS | DT_NOPREFIX);

   for (var i = 0; i < b_text_visable_rows; i++) {
      gr.GdiDrawText(b_text_array[i + s_text], b_font, RGB(0, 0, 0), b_x + 1, b_y + b_text_row_height * i + 2, ww, wh, DT_LEFT);
      gr.GdiDrawText(b_text_array[i + s_text], b_font, b_color, b_x, b_y + b_text_row_height * i, ww, wh, DT_LEFT);
   }

   scrollbar && draw_scrollbar(gr);

   gr.GdiDrawText("", b_font, b_color, 15, 0, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS);
}

function paint(gr) {
   g_img = gdi.Image(files[selected]);
   if (!g_img && nocover) {
      try {
         g_img = gdi.Image(nocover_path);
      } catch (e) {};
   }

   if (g_img) {
      var scale_w = (ww - p_margin * 2) / g_img.Width;
      var scale_h = (wh - p_margin * 2) / g_img.Height;
      var scale = Math.min(scale_w, scale_h);

      if (files.length > 0) {
         g_img = g_img.CreateRawBitmap();
         gr.GdiDrawBitmap(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height);
      } else {
         gr.DrawImage(g_img, p_margin, p_margin, g_img.Width * scale, g_img.Height * scale, 0, 0, g_img.Width, g_img.Height, 0, 100);
      }
   }

   logo_img = gdi.Image(tmp_b_path + "\\download\\" + "last_fm_logo.jpg");
   if (logo_img && files.length == 0 && !nocover) {
      gr.DrawImage(logo_img, p_margin, p_margin, logo_img.Width * 0.8, logo_img.Height * 0.8, 0, 0, logo_img.Width, logo_img.Height, 0, 255);
   }
}

function draw_scrollbar(gr) {
   scrollbar_h = b_text_rows > b_text_visable_rows ? b_text_visable_height * (b_text_visable_rows / b_text_rows) : 0;
   scrollbar_y = s_text > 0 ? s_text * scrollbar_k : 0;

   gr.FillSolidRect(ww - 4, b_y + scrollbar_y, 2, scrollbar_h, a_color);
}

function on_playlist_switch() {
   on_item_focus_change();
}

function on_playback_new_track() {
   on_item_focus_change();
}

function on_playback_dynamic_info_track() {
   on_item_focus_change();
}

function on_playback_stop() {
   on_item_focus_change();
}

function on_selection_changed(metadb) {
   on_item_focus_change();
}

function on_item_focus_change() {
   switch (selection_mode) {
   case 0:
      metadb = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
      break;
   case 1:
      metadb = fb.GetFocusItem();
      break;
   }
   if (metadb)
      on_metadb_changed();
}

function Eval(field) {
   if (!metadb)
      return;
   path = fb.Titleformat("%path%").EvalWithMetadb(metadb);
   //return path.indexOf('://') > 0 ? fb.TitleFormat("[" + field + "]").Eval() : fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb);
   return fb.Titleformat("[" + field + "]").EvalWithMetadb(metadb) ? fb.TitleFormat("[" + field + "]").EvalWithMetadb(metadb) : fb.TitleFormat("[" + field + "]").Eval(true);
}

function on_metadb_changed() {
   if (!metadb)
      return;
   artist = Eval("%artist%");
   filename = clean_filename(artist);
   if (artist != old_artis || select_p_a != select_p_a_old) {
      CollectGarbage();
      g_img = null;
      files = [];
      del_files_from_dir();
      selected = 0;
      s_text = 0;
      text = "";
      get_b_text_array()
      get_pic();
      old_artis = artist;
      select_p_a_old = select_p_a;
   }
}

function get_pic() {
   xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
   var url1 = ("http://www.last.fm/music/" + encodeURIComponent(artist) + "/+" + p_a[select_p_a]);
   xmlhttp1.open("GET", url1, true);
   xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
   xmlhttp1.send();
   xmlhttp1.onreadystatechange = function () {
      if (xmlhttp1.readyState == 4) {
         if (xmlhttp1.status == 200) {
            doc.open();
            var div = doc.createElement("div");
            div.innerHTML = xmlhttp1.responsetext;
            var data = div.getElementsByTagName("img");
            var urls = [];
            for (i = 0; i < data.length; i++) {
               if (data[i].className == "image-list-image") {
                  if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/avatar170s") == 0)
                     urls.push(data[i].src.replace("avatar170s", ""));
               }
               if (data[i].className == "album-grid-album-art") {
                  if (data[i].src.indexOf("http://img2-ak.lst.fm/i/u/300") == 0 && data[i].src.indexOf("c6f59c1e5e7240a4c0d427abd71f3dbb") < 0)
                     urls.push(data[i].src.replace("300", ""));
               }
            }
            for (i = 0; i < Math.min(urls.length, limit); i++) {
               file = "\"" + tmp_b_path + filename + "_" + i + "_" + p_a[select_p_a] + ".jpg" + "\"";
               WshShell.Run(vbs + " " + urls[i] + " " + file, false);
            }
            doc.close();
         }
         get_b_text();
      }
   }
}

function get_files_from_dir() {
   files = [];
   var e = new Enumerator(fso.GetFolder(tmp_b_path).Files);
   while (!e.atEnd()) {
      var name = e.item().Name;
      if (name.indexOf(filename) == 0) {
         files.push(tmp_b_path + name);
      }
      e.moveNext();
   }
}

/*function get_files_from_dir() {
files = [];
files = utils.Glob(tmp_b_path + artist + "*.*").toArray();
}
 */
function get_b_text() {
   xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
   var url2 = ("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist) + "/+wiki");
   xmlhttp2.open("GET", url2, true);
   xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
   xmlhttp2.send();
   xmlhttp2.onreadystatechange = function () {
      if (xmlhttp2.readyState == 4) {
         if (xmlhttp2.status == 200) {
            doc.open();
            var div = doc.createElement("div");
            div.innerHTML = xmlhttp2.responsetext;
            var data = div.getElementsByTagName("div");
            for (i = 0; i < data.length; i++) {
               if (data[i].className == "wiki-content") {
                  text = strip_tags(data[i].innerHTML);
                  break;
               }
            }
            doc.close();

         }
         if (text == "")
            text = if_not_found[abc]; // text = if_not_found[abc];
         get_b_text_array();
      }
   }
}

function strip_tags(t) {
   doc.open();
   var div = doc.createElement("div");
   div.innerHTML = t.replace(/<[Pp][^>]*>/g, "").replace(/<\/[Pp]>/g, "<br>").replace(/\n/g, "<br>");
   var text = div.innerText;
   doc.close();
   return text;
}

function get_b_text_array() {
   artist_x = txt_x + t_margin;
   artist_y = txt_y + t_margin;
   strings_array = [];
   b_text_array = [];

   temp_bmp = gdi.CreateImage(1, 1);
   temp_gr = temp_bmp.GetGraphics();

   b_x = txt_x + t_margin;
   b_y = txt_y + temp_gr.CalcTextHeight("text", a_font) + t_margin * 2;

   b_text_row_height = temp_gr.CalcTextHeight("text", b_font)
      string_width = Math.max(ww - b_x - 10, 0);

   if (text)
      strings_array = temp_gr.EstimateLineWrap(text, b_font, string_width).toArray();

   for (var i = 0; i < strings_array.length; i += 2) {
      b_text_array.push(strings_array[i].replace(/^\s+|\s+$/g, ""));
   }

   b_text_rows = b_text_array.length;
   b_text_visable_rows = Math.round((wh - b_y - 10) / b_text_row_height);
   b_text_visable_height = Math.round(wh - b_y - 10);

   temp_bmp.ReleaseGraphics(temp_gr);
   temp_bmp.Dispose();
   temp_gr = null;
   temp_bmp = null;

   if (b_text_visable_rows + s_text > b_text_rows && s_text > 0) {
      s_text = b_text_rows - b_text_visable_rows;
   };

   scrollbar_k = b_text_visable_height / b_text_rows;
   window.Repaint();
}

function on_mouse_rbtn_up(x, y) {
   var _menu = window.CreatePopupMenu();
   var _firstgroup = window.CreatePopupMenu();
   var i = 1;

   MF_ENABLED = 0x00000000;
   MF_GRAYED = 0x00000001;
   MF_SEPARATOR = 0x00000800;

   _firstgroup.AppendTo(_menu, MF_ENABLED, "Language / Язык");

   _firstgroup.AppendMenuItem(MF_ENABLED, 101, "EN - English");
   _firstgroup.AppendMenuItem(MF_ENABLED, 102, "RU - Русский");
   _firstgroup.AppendMenuItem(MF_ENABLED, 103, "ES - Español");
   _firstgroup.AppendMenuItem(MF_ENABLED, 104, "FR - Français");
   _firstgroup.AppendMenuItem(MF_ENABLED, 105, "IT - Italiano");
   _firstgroup.AppendMenuItem(MF_ENABLED, 106, "JA - 日本語");
   _firstgroup.AppendMenuItem(MF_ENABLED, 107, "PL - Polski");
   _firstgroup.AppendMenuItem(MF_ENABLED, 108, "PT - Português");
   _firstgroup.AppendMenuItem(MF_ENABLED, 109, "DE - Deutsch");
   _firstgroup.AppendMenuItem(MF_ENABLED, 110, "SV - Svenska");
   _firstgroup.AppendMenuItem(MF_ENABLED, 111, "TR - Türkçe");
   _firstgroup.AppendMenuItem(MF_ENABLED, 112, "ZH - 中国人");

   _menu.CheckMenuRadioItem(101, 112, abc + 101);
   _menu.EnableMenuItem(abc + 101, 1);

   _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);

   _menu.AppendMenuItem(MF_ENABLED, 3, _("Prefer now playing"));
   _menu.AppendMenuItem(MF_ENABLED, 4, _("Follow selected track"));
   _menu.CheckMenuRadioItem(3, 4, selection_mode + 3);
   _menu.EnableMenuItem(selection_mode + 3, 1);

   _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   _menu.AppendMenuItem(MF_ENABLED, 5, _("Artist pictures"));
   _menu.AppendMenuItem(MF_ENABLED, 6, _("Albums pictures"));
   _menu.CheckMenuRadioItem(5, 6, select_p_a + 5);
   _menu.EnableMenuItem(select_p_a + 5, 1);

   _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   var is_artist = artist ? MF_ENABLED : MF_GRAYED;
   _menu.AppendMenuItem(is_artist, 7, _("last.fm Artist"));

   //    if (ShiftDown) {

   if (("Reload" in window)) {
      _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
      _menu.AppendMenuItem(MF_ENABLED, 10, _("Reload"));
   }
   _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
   _menu.AppendMenuItem(MF_ENABLED, 20, _("Properties"));
   _menu.AppendMenuItem(MF_ENABLED, 30, _("Configure..."));
   //    }

   ret = _menu.TrackPopupMenu(x, y);

   switch (ret) {
   case 101:
      abc = 0;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 102:
      abc = 1;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 103:
      abc = 2;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 104:
      abc = 3;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 105:
      abc = 4;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 106:
      abc = 5;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 107:
      abc = 6;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 108:
      abc = 7;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 109:
      abc = 8;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 110:
      abc = 9;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 111:
      abc = 10;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 112:
      abc = 11;
      window.SetProperty("abc", abc);
      s_text = 0;
      text = "";
      get_b_text();
      break;
   case 3:
      selection_mode = 0;
      window.SetProperty("selection_mode", selection_mode);
      on_item_focus_change();
      break;
   case 4:
      selection_mode = 1;
      window.SetProperty("selection_mode", selection_mode);
      on_item_focus_change();
      break;
   case 5:
      select_p_a = 0;
      window.SetProperty("pictures/albums", select_p_a);
      on_metadb_changed();
      break;
   case 6:
      select_p_a = 1;
      window.SetProperty("pictures/albums", select_p_a);
      on_metadb_changed();
      break;
   case 7:
      WshShell.run("http://www.last.fm/" + abc_lang[abc] + "music/" + encodeURIComponent(artist));
      break;
   case 10:
      window.Reload();
      break;
   case 20:
      window.ShowProperties();
      break;
   case 30:
      window.ShowConfigure();
      break;
   }
   _menu.Dispose();
   return true;
}

var timer = window.SetInterval(on_timer, 1000);
var step = 0;
var set_cycle = false;
var dis_timer, dis = 0;

function on_timer(id) {
   step = set_cycle || cycle == 0 ? 0 : step + 1;
   if (files.length == 0) {
      get_files_from_dir();
      window.Repaint();
   };

   if (cycle > 0 && step >= cycle) {
      selected = selected >= files.length - 1 ? 0 : selected = selected + 1;
      window.Repaint();
      step = 0;
   }
}

function on_key_down(vkey) {
   if (vkey == 16) {
      set_cycle = true;
      dis_set();
      window.Repaint();
   }
}

function dis_set() {
   dis = 0;
   dis_timer && window.ClearInterval(dis_timer);
   dis_timer = window.SetInterval(function () {
         if (set_cycle) {
            dis++;
            if (dis == 1) {
               set_cycle = false;
               window.ClearInterval(dis_timer);
               window.Repaint();
            };
         }
      }, 1000);
}

var delay = false;

function fdelay() {
   var delay_timer = window.SetTimeout(function () {
         delay = false;
         window.ClearTimeout(delay_timer);
      }, 200);
}

function del_files_from_dir() {
   var del_files = [];
   var e = new Enumerator(fso.GetFolder(tmp_b_path).Files);
   while (!e.atEnd()) {
      var name = e.item().Name;
      try {
         fso.deleteFile(tmp_b_path + name);
      } catch (e) {};
      e.moveNext();
   }
}

/*
function del_files_from_dir() {
del_files = [];
del_files = utils.Glob(tmp_b_path + "*.*").toArray();


for (i in del_files) {
try {
fso.deleteFile(del_files[i]);
} catch(e) {};
}
}
 */

function load_last_fm_logo() {
   if (!fso.FileExists(tmp_b_path + "\\download\\" + "last_fm_logo.jpg")) {
      var url = "http://www.last.fm/static/images/logo_beta.png?eb6d3ca20e73"
         var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_logo.jpg" + "\"";
      WshShell.Run(vbs + " " + url + " " + file, false);
      var url = "http://static-web.last.fm/static/images/favicon.702b239b6194.ico"
         var file = "\"" + tmp_b_path + "\\download\\" + "last_fm_ico.ico" + "\"";
      WshShell.Run(vbs + " " + url + " " + file, false);
   }
}

function create_download_file() {
   try {
      file = fso.CreateTextFile(tmp_b_path + "\\download\\" + "download.vbs")

         var text =
         "If (WScript.Arguments.Count <> 2) Then" + "\n\r" +
         "   WScript.Quit" + "\n\r" +
         "End If" + "\n\r" + "\n\r" +

         "url = WScript.Arguments(0)" + "\n\r" +
         "file = WScript.Arguments(1)" + "\n\r" + "\n\r" +

         "Set objFSO = Createobject(" + '"Scripting.FileSystemObject"' + ")" + "\n\r" +
         "If objFSO.Fileexists(file) Then" + "\n\r" +
         "   Set objFSO = Nothing" + "\n\r" +
         "   WScript.Quit" + "\n\r" +
         "End If" + "\n\r" + "\n\r" +

         "Set objXMLHTTP = CreateObject(" + '"MSXML2.XMLHTTP"' + ")" + "\n\r" +
         "objXMLHTTP.open " + '"GET"' + ", url,false" + "\n\r" +
         "objXMLHTTP.send()" + "\n\r" + "\n\r" +

         "If objXMLHTTP.Status = 200 Then" + "\n\r" +
         "   Set objADOStream = CreateObject(" + '"ADODB.Stream"' + ")" + "\n\r" +
         "   objADOStream.Open" + "\n\r" +
         "   objADOStream.Type = 1" + "\n\r" +
         "   objADOStream.Write objXMLHTTP.ResponseBody" + "\n\r" +
         "   objADOStream.Position = 0" + "\n\r" +
         "   objADOStream.SaveToFile file" + "\n\r" +
         "   objADOStream.Close" + "\n\r" +
         "   Set objADOStream = Nothing" + "\n\r" +
         "End If" + "\n\r" + "\n\r" +

         "Set objFSO = Nothing" + "\n\r" +
         "Set objXMLHTTP = Nothing";

      file.WriteLine(text);
      file.Close();
   } catch (e) {};
}

function on_mouse_move(x, y) {
   window.SetCursor(32649);

   text_scroll = x >= txt_x && x < ww - 20 && y >= txt_y ? true : false;
   sb_scroll = x > ww - 20 && y >= txt_y ? true : false;
   pic_scroll = !text_scroll && !sb_scroll ? true : false;

   if (k_down) {
      txt_x = x - delta_x;
      txt_y = y - delta_y;

      txt_x = txt_x <= 0 ? 0 : txt_x >= ww - 50 ? ww - 50 : txt_x;
      txt_y = txt_y <= 0 ? 0 : txt_y >= wh - 50 ? wh - 50 : txt_y;
      get_b_text_array();
   }

   if (sb_down && scrollbar) {
      posy = y + delta_y;
      s_text = y + delta_y >= 0 ? y + delta_y <= (b_text_rows - b_text_visable_rows) * scrollbar_k ? Math.round(posy / scrollbar_k) : b_text_rows - b_text_visable_rows : 0;
      window.Repaint();
   }
}

function on_mouse_wheel(delta) {
   ShiftDown = utils.IsKeyPressed(0x10) ? true : false;

   if (!delay && pic_scroll && !ShiftDown) {
      delay = true;
      fdelay();
      get_files_from_dir();
      if (delta < 0) {
         selected = selected <= 0 ? files.length - 1 : selected = selected - 1
      };
      if (delta > 0) {
         selected = selected >= files.length - 1 ? 0 : selected = selected + 1
      };

   }

   if (text_scroll && !ShiftDown) {
      if (b_text_rows > b_text_visable_rows) {
         if (delta < 0) {
            s_text = b_text_rows - s_text <= b_text_visable_rows ? b_text_rows - b_text_visable_rows : s_text += 1
         }
         if (delta > 0) {
            s_text = s_text <= 0 ? 0 : s_text -= 1
         }

      }
   }

   if (!delay && text_scroll && ShiftDown) {
      delay = true;
      fdelay();
      if (delta < 0) {
         font_size_b = font_size_b <= min_font_size ? min_font_size : font_size_b - 2;
      };
      if (delta > 0) {
         font_size_b = font_size_b >= max_font_size ? max_font_size : font_size_b + 2;
      };
      window.SetProperty("font size: biography", font_size_b);
      get_font();
      get_b_text_array();
   }

   if (set_cycle && pic_scroll) {
      if (delta < 0) {
         cycle = cycle <= 0 ? 0 : cycle - 5;
      };
      if (delta > 0) {
         cycle = cycle >= 60 ? 60 : cycle + 5;
      };
      window.SetProperty("auto cycle (sec)", cycle);

   }
   window.Repaint();
}

function on_mouse_lbtn_down(x, y) {
   if (text_scroll) {
      k_down = true;
      delta_x = x - txt_x;
      delta_y = y - txt_y;
   }
   if (sb_scroll) {
      sb_down = true;
      posy = s_text * scrollbar_k;
      delta_y = posy - y;
   }
}

function on_mouse_lbtn_up(x, y) {
   window.SetProperty("txt_x", txt_x);
   window.SetProperty("txt_y", txt_y);
   k_down = false;
   sb_down = false;
}

function on_mouse_lbtn_dblclk(x, y) {
   if (text_scroll) {
      abc = abc == 1 ? 0 : 1;
      window.SetProperty("abc", abc);
      s_text = 0;
      b_text_array = [];
      text = "";
      get_b_text();
   }
   if (files[selected] && pic_scroll)
      WshShell.run('"' + files[selected] + '"');
}

function on_mouse_leave() {
   window.SetCursor(32512);
   window.Repaint();
}

function on_size() {
   ww = window.Width;
   wh = window.Height;

   txt_x = window.GetProperty("txt_x");
   txt_y = window.GetProperty("txt_y");

   txt_x = txt_x >= ww - 50 && txt_x >= 0 ? ww - 50 : txt_x;
   txt_y = txt_y >= wh - 50 && txt_y >= 0 ? wh - 50 : txt_y;

   get_b_text_array();
}
zeremy
07.03.2016, 22:32
 
Раздел: Секреты foobar2000
Тема: Скрипты для foo_uie_wsh_panel_mod
Ответы: 3018
Просмотры: 855400
След.